Home > DeveloperSection > Forums > Can you call Directory.GetFiles() with multiple filters?
Pravesh Singh
Pravesh Singh

Total Post:101

Posted on    November-14-2013 3:26 AM

 C# C# 

 1 Reply(s)
 2194  View(s)
Rate this:

I am trying to use the Directory.GetFiles() method to retrieve a list of files of multiple types, such as mp3's and jpg's. I have tried both of the following with no luck:

Directory.GetFiles("C:\\path", "*.mp3|*.jpg", SearchOption.AllDirectories);

Directory.GetFiles("C:\\path", "*.mp3;*.jpg", SearchOption.AllDirectories);

Is there a way to do this in one call?

ezra heywood
ezra heywood

Total Post:145

Posted on    November-14-2013 4:47 AM

Hi Pravesh,

You can try this:
var files = Directory.GetFiles("C:\\path", "*.mp3", SearchOption.AllDirectories).Union(Directory.GetFiles("C:\\path", "*.jpg", SearchOption.AllDirectories));

Don't want to miss updates? Please click the below button!

Follow MindStick