CAN YOU CALL DIRECTORY.GETFILES() WITH MULTIPLE FILTERS?

Pravesh Singh

Total Post:101

Points:709
Posted by  Pravesh Singh
C# 
C#
 2247  View(s)
Ratings:
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?

  1. ezra heywood

    Post:145

    Points:1019
    Re: Can you call Directory.GetFiles() with multiple filters?

    Hi Pravesh,


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


Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!