Problem creating FileInfo Array

A

Antonio

Good morning,
I've the following file system :

C: -> HTML -> Aziende -> Azienda_1 -> a.jpg
-> Azienda_2 -> a.jpg
...
-> Azienda_N -> a.jpg

my desire is to create an array of fileinfo containing the a.jpg ,
a.jpg , ... , a.jpg
in a way that I could bind this to a datagrid to show some properties
of these files.
I tried the following but it is not ok

FileInfo[] fi ;
DirectoryInfo dirInfo = new DirectoryInfo("C:\HTML\Aziende");
DirectoryInfo[] di = dirInfo.GetDirectories();
int i = 0;
fi = new FileInfo[1000];
foreach (DirectoryInfo dri in di)
{
fi[i++] = dri.GetFiles("a.jpg")[0];
}

the error is System.IndexOutOfRangeException


could you help me to solve this problem and to crate the array of
FileInfo types ??

Thanks ...


Antonio
 
M

Maqsood Ahmed

I guess the problem is not in create FileInfo array. Its in
dri.GetFiles("filename")[0]. Some directories might not have "a.jpg"
file, and return a zero length FileInfo array. You need to check if
length of the return array is greater than zero.
Cheers!!

Maqsood Ahmed
Kolachi Advanced Technologies
http://www.kolachi.net
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top