Thanks.
FileSearch isn't deprecated in 2007, it's gone. Puzzling.
This isn't fully cooked yet, but let me know how you get on.
Function FindFilesUDF(sPatt As String, sDir As String) As Variant
' shg 2009-06
Dim nDir As Long
Dim nFile As Long
Dim sFiles As String
FindFilesUDF = FindFileRec(sDir, sPatt, nDir, nFile)
If Len(FindFilesUDF) Then
FindFilesUDF = Split(Left(FindFilesUDF, Len(FindFilesUDF) - 1), vbLf)
Else
FindFilesUDF = Empty
End If
End Function
Private Function FindFileRec(ByVal sDir As String, sPatt As String, _
nDir As Long, nFile As Long, _
Optional bStatusBar As Boolean = False) As String
' shg 2009-06
Const iAttr As Long = vbNormal Or vbHidden Or vbSystem Or vbReadOnly
Dim tFld As Folder
Dim tFil As File
Dim sFile As String
On Error GoTo Oops
Set oFld = oFSO.GetFolder(sDir)
Application.StatusBar = "Searching " & sDir & " ..."
sFile = Dir(sDir & "\", iAttr)
Do While Len(sFile)
If LCase(sFile) Like sPatt Then
nFile = nFile + 1
FindFileRec = FindFileRec & sDir & "\" & sFile & vbLf
End If
sFile = Dir()
DoEvents
Loop
nDir = nDir + 1
If oFld.SubFolders.Count Then
For Each tFld In oFld.SubFolders
FindFileRec = FindFileRec + FindFileRec(tFld.Path, sPatt, nDir, nFile)
DoEvents
Next
End If
Exit Function
Oops:
sFile = ""
Resume Next
End Function
It REQUIRES a reference to Microsoft Scripting Runtime.
FindFilesLike("*Metrics33*.xls", "E:\Work\Work\MetricResults_010908")
will return a variant that is either Empty or contains a list of found files.
Bookmarks