Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Want to list all Image Files in a folder using C# [duplicate]

Tags:

c#

Possible Duplicate:
GetFiles with multiple extentions

is there a function like GetFiles that takes more then 1 file type like

DirectoryInfo di = new DirectoryInfo("c:/inetpub/wwwroot/demos");
FileInfo[] rgFiles = di.GetFiles("*.bmp, *.jpg, etc");
like image 991
Kimtho6 Avatar asked Dec 10 '22 12:12

Kimtho6


1 Answers

AFAIK, this isn't directly possible.

Instead, you can get every file, then filter the array:

HashSet<string> allowedExtensions = new HashSet<string>(extensionArray, StringComparer.OrdinalIgnoreCase);
FileInfo[] files = Array.FindAll(dirInfo.GetFiles(), f => allowedExtensions.Contains(f.Extension));

extensionArray must include . before each extension, but is case-insensitive.

like image 148
SLaks Avatar answered Feb 22 '23 09:02

SLaks