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

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

    Just found an another way to do it. Still not one operation, but throwing it out to see what other people think about it.

    private void getFiles(string path)
    {
        foreach (string s in Array.FindAll(Directory.GetFiles(path, "*", SearchOption.AllDirectories), predicate_FileMatch))
        {
            Debug.Print(s);
        }
    }
    
    private bool predicate_FileMatch(string fileName)
    {
        if (fileName.EndsWith(".mp3"))
            return true;
        if (fileName.EndsWith(".jpg"))
            return true;
        return false;
    }
    

提交回复
热议问题