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

前端 未结 26 2979
逝去的感伤
逝去的感伤 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条回答
  •  猫巷女王i
    2020-11-22 05:52

    What about

    string[] filesPNG = Directory.GetFiles(path, "*.png");
    string[] filesJPG = Directory.GetFiles(path, "*.jpg");
    string[] filesJPEG = Directory.GetFiles(path, "*.jpeg");
    
    int totalArraySizeAll = filesPNG.Length + filesJPG.Length + filesJPEG.Length;
    List filesAll = new List(totalArraySizeAll);
    filesAll.AddRange(filesPNG);
    filesAll.AddRange(filesJPG);
    filesAll.AddRange(filesJPEG);
    

提交回复
热议问题