'This is a modified version of your code - I have put in remarks, where changes have been made:
'1: Parameters are declared as ByVal as a default, so there's no need to type it every time.
'2: There is no need to use ByRef on a List, since it is a reference type and thus can be added
' to and removed from both with ByVal or ByRef declaration.
'3: List(Of T) performs better than ArrayList in most cases and is type-safe (source MSDN).
'4: Changed path to Path and listOfFiles to ListOfFiles to have naming consistancy.
Private Sub YourSearchAndAddToListWithFilter(Path As String, Recursive As Boolean, ListOfFilters As List(Of String), ListOfFiles As List(Of FileInfo))
If Not Directory.Exists(Path) Then Exit Sub
Dim InitDirInfo As New DirectoryInfo(Path) '5: Changed from initDirInfo
For Each oFileInfo As FileInfo In InitDirInfo.GetFiles() '6: Added type and Method paranthesis.
'Application.DoEvents() '7: Commented out
For Each Filter As String In ListOfFilters '8: Changed to foreach which is more natural
If oFileInfo.Name Like Filter Then '9: Unnecessary paranthesis.
ListOfFiles.Add(oFileInfo)
End If
Next
Next
'The 2 nested loops above can be written in a more natural way as:
'For Each Filter As String In ListOfFilters
' For Each oFileInfo As FileInfo In InitDirInfo.GetFiles(Filter)
' ListOfFiles.Add(oFileInfo)
' Next
'Next
If Recursive Then
For Each oDirInfo As DirectoryInfo In InitDirInfo.GetDirectories() '10: Added type and paranthesis.
YourSearchAndAddToListWithFilter(oDirInfo.FullName, True, ListOfFilters, ListOfFiles)
Next
End If
End Sub
Public Sub YourSearchForMedia()
'Here I mainly changed names to follow your own naming conventions and changed the loop from
'an integer loop to the more natural foreach. Also MsgBox() should be MessageBox.Show().
'If you want to keep spaces in your StringFilterList, you should use something like:
' StringFilterList.Split(",").Select(Function(s) Trim(s)).ToList()
'instead of just splitting.
Dim StringFilterList As String = "*.png,*.bmp,*oa*"
Dim ListOfFilenameFilters As List(Of String) = StringFilterList.Split(",").ToList()
Dim StringFolderPath As String = "<mydir>"
Dim SearchSubFolders As Boolean = True
Dim ListOfFilesFoundViaSearch As New List(Of FileInfo)
YourSearchAndAddToListWithFilter(StringFolderPath, SearchSubFolders, ListOfFilenameFilters, ListOfFilesFoundViaSearch)
For Each oFileInfo As FileInfo In ListOfFilesFoundViaSearch
'MessageBox.Show(oFileInfo.FullName)
Console.WriteLine(oFileInfo.FullName) 'Using this instead of having 1000 files displayed.
Next
End Sub