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

前端 未结 26 2758
逝去的感伤
逝去的感伤 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 05:54

    I can't use .Where method because I'm programming in .NET Framework 2.0 (Linq is only supported in .NET Framework 3.5+).

    Code below is not case sensitive (so .CaB or .cab will be listed too).

    string[] ext = new string[2] { "*.CAB", "*.MSU" };
    
    foreach (string found in ext)
    {
        string[] extracted = Directory.GetFiles("C:\\test", found, System.IO.SearchOption.AllDirectories);
    
        foreach (string file in extracted)
        {
            Console.WriteLine(file);
        }
    }
    

提交回复
热议问题