I need to list all of the images in a folder using C#.
I searched Stack Overflow and found some threads talking about it, but the questions were covering PHP. I need to do this with C#.
DirectoryInfo di = new DirectoryInfo(@"C:\YourImgDir");
FileInfo[] Images = di.GetFiles("*.jpg");
You can substitute whatever image file extensions you so desire.
这适用于C#:
string[] files = Directory.GetFiles("Location of Files", "*.jpg"); //.png, bmp, etc.
You can use Directory.GetFiles
to get the filenames of files in a directory:
var files = Directory.GetFiles("directory_path", "*.jpg");
You can change .jpg
for any other file type. The asterisk is a wildcard character.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.