Well, mine doesn't do it recursively, but it will give you a list of files and let you manage them however you want:
Code:
Public Function GetFiles(colDirList As Collection, ByVal FilePath As String, FileName As String) As Boolean
Dim strTemp As String
Dim colFolders As New Collection
FilePath = TrailingSlash(FilePath)
strTemp = Dir(FilePath & FileName)
Do While strTemp <> vbNullString
colDirList.Add FilePath & strTemp
strTemp = Dir
Loop
End Function
Public Function TrailingSlash(FilePath As Variant) As String
If Len(FilePath) > 0& Then
If Right(FilePath, 1&) = "\" Then
TrailingSlash = FilePath
Else
TrailingSlash = FilePath & "\"
End If
End If
End Function
The Function GetFiles() returns a Collection (basically an array, just a little fancier) that includes all files in a Folder. The Function TrailingSlash() just makes sure there's a backslash at the end of your Folder name so that it can properly append the filename.
Example (simple) usage:
Code:
' Lists all files in the Folder C:\WINDOWS\Temp that have a .TMP extension and lists them (one at a time) in a Message Box.
Dim colDirList As New Collection
Dim strFilename as String
Dim strFolder as String
Dim varItem As Variant
strFolder = "C:\WINDOWS\Temp" ' Doesn't matter if you include the trailing slash or not!
strFilename = "*.tmp" ' Can use Wildcards!
Call GetFiles(colDirList, strFolder, strFile) ' populates our Collection
For Each varItem In colDirList
' varItem includes the full Folder & Filename all as a single string
MsgBox varItem
Next varItem