filesInDirectory = Directory.GetFiles(PictureDirectory, "*.jpg");Works fine but:
filesInDirectory = Directory.GetFiles(PictureDirectory, "*.jpg;*.bmp");Does not work correctly at all, Is there any way to do this, without calling multiple times and joining arrays
Also it seems to just return them in alphabetical order, is there anyway to return them in the way they are sorted/being viewed in Explorer
Thanks!

Using GetFiles
Keyser
As for multiple extensions no Directory doesn't support it. The biggest issue is that ; is a valid filename character so it would have no way of knowing that you wanted multiple extensions vs. a single one. You'd have to use an overload that accepted an array of extensions to search for. Nevertheless it is pretty easy to do what you want (perhaps wrapping it in a custom function for others).
public static string[] GetFiles ( string pathName, params string[] patterns )
{
StringCollection coll = new StringCollection();
foreach (string pattern in patterns)
{
string[] files = Directory.GetFiles(pathName, pattern);
coll.AddRange(files);
};
string[] arr = new string[coll.Count];
coll.CopyTo(arr, 0);
return arr;
}
Of course you can sort the array however you want.
Michael Taylor - 11/26/05
noslen
Thanks! GetFiles always seems to return the items in alphabetical order. Are there other ways to return files from a directory (or simply the names). Where I got this idea was from the Windows Picture and Fax Viewer. Whenever you flip through the images it's always in the exact order that it's displayed in the folder. I don't know if this is how functions like FindNextFile in Win32 work or if they are doing something special.
Just wondering if anyone might have some ideas to try.
markiemarkie
Here it is.