tags:

views:

24

answers:

3

For example, given the folder: C:\images\a

How could I retrieve a collection of all of the images in that folder? Thank you.

+1  A: 

For just simple string paths, you can use the GetFiles static method in the Directory class (System.IO).

string[] files = Directory.GetFiles(path, "*.jpg", SearchOption.AllDirectories);

For more information about the files, you could use the DirectoryInfo class to retrieve FileInfo objects about each file.

FileInfo[] fileInfos = new DirectoryInfo(path).GetFiles("*.jpg", SearchOption.AllDirectories);
Anthony Pegram
A: 

Call Directory.GetFiles.

If you want to recursively search subfolders, pass SearchOption.AllDirectories.

SLaks
A: 

One of the ways you could do it is:

DirectoryInfo di = new DirectoryInfo("c:/demos");
 FileInfo[] rgFiles = di.GetFiles("*.jpgs");
 foreach(FileInfo fi in rgFiles)
 {
  //do your stuff       
 }
VoodooChild