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

前端 未结 26 2965
逝去的感伤
逝去的感伤 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:11

    There is also a descent solution which seems not to have any memory or performance overhead and be quite elegant:

    string[] filters = new[]{"*.jpg", "*.png", "*.gif"};
    string[] filePaths = filters.SelectMany(f => Directory.GetFiles(basePath, f)).ToArray();
    

提交回复
热议问题