开发者

Search In a Directory and Subdirectories and List All Matched Files and Folder

开发者 https://www.devze.com 2023-04-05 07:34 出处:网络
I want Search In a Directory for multiple pattern ( For Example : *.jpg,*.png,Davood开发者_Go百科,*.dj ) that Result shoud return all files and folders that matched with my pattern,

I want Search In a Directory for multiple pattern ( For Example : *.jpg,*.png,Davood开发者_Go百科,*.dj ) that Result shoud return all files and folders that matched with my pattern,

can any body help to me ?

Thanks in advance


Modified to search multiple 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)

This will return a List(Of String) that match yourPatternToMatch

0

精彩评论

暂无评论...
验证码 换一张
取 消