我希望在目录中搜索多种模式(例如:*.jpg,*.png,Davood,*.dj
),结果应该返回与我的模式匹配的所有文件和文件夹,
任何人都可以帮助我吗?
提前致谢
答案 0 :(得分:1)
修改以搜索多个pattherns
Dim Patterns As String() = yourPatterns.Split(","c)
Dim matchedDirectories As New List(Of String)
Dim matchedFiles As New List(Of String)
For Each pattern in Patterns
Dim targetDirectory As New System.IO.DirectoryInfo(yourDirectoryPath)
Dim yourPatternToMatch As String = pattern
matchedDirectories.Concat(targetDirectory.GetDirectories(yourPatternToMatch, System.IO.SearchOption.AllDirectories).AsEnumerable.Select(Function(d) d.FullName)))
matchedFiles.Concat(targetDirectory.GetFiles(yourPatternToMatch, System.IO.SearchOption.AllDirectories).AsEnumerable.Select(Function(f) f.FullName))
Next
return matchedDirectories.Concat(matchedFiles)
这将返回与List(Of String)
yourPatternToMatch