For example, given the folder: C:\images\a
How could I retrieve a collection of all of the images in that folder? Thank you.
For example, given the folder: C:\images\a
How could I retrieve a collection of all of the images in that folder? Thank you.
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);
Call Directory.GetFiles
.
If you want to recursively search subfolders, pass SearchOption.AllDirectories
.
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
}