title: Find files with filename filter
body: <p>I am using VB.net VS2012 and am having trouble with getting a list of files with a filter.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>Public Function SearchAndAddToListWithFilter(ByVal path As String, ByVal Recursive As Boolean, arrayListOfFilters As ArrayList, ByRef listOfFiles As List(Of FileInfo))
      If Not Directory.Exists(path) Then Exit Function
  
      Dim initDirInfo As New DirectoryInfo(path)
  
      For Each oFileInfo In initDirInfo.GetFiles
          Application.DoEvents()
          For x = 0 To arrayListOfFilters.Count - 1
              If (oFileInfo.Name Like arrayListOfFilters(x)) Then
                  listOfFiles.Add(oFileInfo)
              End If
          Next
      Next
  
      If Recursive Then
          For Each oDirInfo In initDirInfo.GetDirectories
              SearchAndAddToListWithFilter(oDirInfo.FullName, True, arrayListOfFilters, listOfFiles)
          Next
      End If
  
  End Function
  </code></pre>
  
  <p>And here is an example of how to use it:</p>
  
  <pre><code>    Dim stringFilterList As String = "*.mp3, *.docx, *.mp3, *.txt"
      Dim arrayListOfFilenameFilters As New ArrayList(stringFilterList.Split(","))
      Dim stringFolderPath As String = "C:\temp\folder\"
      Dim booleanSearchSubFolders As Boolean = True
  
      Dim listOfFilesFoundViaSearch As New List(Of FileInfo)
      SearchAndAddToListWithFilter(stringFolderPath, booleanSearchSubFolders, arrayListOfFilenameFilters, listOfFilesFoundViaSearch)
  
      For x = 0 To listOfFilesFoundViaSearch.Count - 1
          MsgBox(listOfFilesFoundViaSearch(x).FullName)
      Next
  </code></pre>
  
  <p>For some reason, the code only adds the files to the list that satisy the first condition in the list of filters.</p>
  
  <p>Can I please have some help to get this code working?</p>
  
  <p>Thank you.</p>