在目录和子目录中搜索并列出所有匹配的文件和文件夹

时间:2011-09-15 15:57:10

标签: vb.net

我希望在目录中搜索多种模式(例如:*.jpg,*.png,Davood,*.dj),结果应该返回与我的模式匹配的所有文件和文件夹

任何人都可以帮助我吗?

提前致谢

1 个答案:

答案 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