How can I find both file types *.gif and *.jpg using DirectoryInfo.GetFiles
function in C# ?
When I try this code:
string pattern = "*.gif|*.jpg";
FileInfo[] files = dir.GetFiles(pattern);
The exception "Illegal characters in path." is thrown.
THere is no way to combine into one string pattern, you have to store patterns in a list:
var extensions = new[] { "*.gif", "*.jpg" };
var files = extensions.SelectMany(ext => dir.GetFiles(ext));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With