Can you call Directory.GetFiles() with multiple filters?

前端 未结 26 2453
逝去的感伤
逝去的感伤 2020-11-22 05:25

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 t

26条回答
  •  鱼传尺愫
    2020-11-22 06:09

    If you are using VB.NET (or imported the dependency into your C# project), there actually exists a convenience method that allows to filter for multiple extensions:

    Microsoft.VisualBasic.FileIO.FileSystem.GetFiles("C:\\path", Microsoft.VisualBasic.FileIO.SearchOption.SearchAllSubDirectories, new string[] {"*.mp3", "*.jpg"});
    

    In VB.NET this can be accessed through the My-namespace:

    My.Computer.FileSystem.GetFiles("C:\path", FileIO.SearchOption.SearchAllSubDirectories, {"*.mp3", "*.jpg"})
    

    Unfortunately, these convenience methods don't support a lazily evaluated variant like Directory.EnumerateFiles() does.

提交回复
热议问题