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

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

    /// 
    /// Returns the names of files in a specified directories that match the specified patterns using LINQ
    /// 
    /// The directories to seach
    /// the list of search patterns
    /// 
    /// The list of files that match the specified pattern
    public static string[] GetFilesUsingLINQ(string[] srcDirs,
         string[] searchPatterns,
         SearchOption searchOption = SearchOption.AllDirectories)
    {
        var r = from dir in srcDirs
                from searchPattern in searchPatterns
                from f in Directory.GetFiles(dir, searchPattern, searchOption)
                select f;
    
        return r.ToArray();
    }
    

提交回复
热议问题