DJafari
DJafari

Reputation: 13545

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

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

can any body help to me ?

Thanks in advance

Upvotes: 0

Views: 1537

Answers (1)

msarchet
msarchet

Reputation: 15242

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

Upvotes: 1

Related Questions