Below is a general purpose utility which will find either the first, or all files in and beneath the parent directory which meet a given file specification. It returns a collection which contains a list of the matching file(s).
Private Sub GetFileCollection()
Dim lCol_FoundFiles As Collection
Dim lBol_FoundOne As Boolean
Dim lStr_Pattern As String
Dim lStr_FileSpec As String
Dim lInt_Idx As Integer
Dim lStr_ThisChar As String
Dim lStr_ParentDir As String
lStr_ParentDir = "c:\Program Files\"
lStr_FileSpec = "*.exe"
lStr_Pattern = ""
For lInt_Idx = 1 To Len(lStr_FileSpec)
lStr_ThisChar = Mid(lStr_FileSpec, lInt_Idx, 1)
Select Case lStr_ThisChar
Case "*"
lStr_Pattern = lStr_Pattern & "\w*"
Case "?"
lStr_Pattern = lStr_Pattern & "."
Case "."
lStr_Pattern = lStr_Pattern & "\."
Case Else
lStr_Pattern = lStr_Pattern & "[" & UCase(lStr_ThisChar) & lStr_ThisChar & "]"
End Select
Next lInt_Idx
lStr_Pattern = lStr_Pattern & "$"
Set lCol_FoundFiles = New Collection
lBol_FoundOne = FindFiles(lCol_FoundFiles, lStr_ParentDir, lStr_Pattern, True)
If (lBol_FoundOne = True) Then
For lInt_Idx = 1 To lCol_FoundFiles.Count
' <process file: lCol_FoundFiles.Item(lint_idx) >
Next lInt_Idx
End If
End Sub
'-------------------------------------------------------
Public Function FindFiles(rCol_FileList As Collection, rStr_Parent As String, rStr_Pattern As String, rBol_FindAll As Boolean) As Boolean
Dim lStr_CheckFile As String
Dim lInt_Idx As Integer
Dim lBol_FileFound As Boolean
Dim lInt_FileType As Integer
Dim lCol_SubDirs As New Collection
Dim lReg_FileString As New RegExp
If (Right(rStr_Parent, 1) <> "\"

Then
rStr_Parent = rStr_Parent & "\"
End If
lReg_FileString.Pattern = rStr_Pattern
lStr_CheckFile = Dir(rStr_Parent, vbDirectory)
lBol_FileFound = False
While (Len(lStr_CheckFile) > 0)
If (UCase(lStr_CheckFile) = "PAGEFILE.SYS"

Then
lStr_CheckFile = Dir
Else
If (Left(lStr_CheckFile, 1) = "."

Then
lStr_CheckFile = Dir
Else
lInt_FileType = GetAttr(rStr_Parent & lStr_CheckFile) And vbDirectory
If (lInt_FileType = vbDirectory) Then
lCol_SubDirs.Add (rStr_Parent & lStr_CheckFile)
lStr_CheckFile = Dir
Else
If (lReg_FileString.Test(lStr_CheckFile) = True) Then
rCol_FileList.Add rStr_Parent & lStr_CheckFile
lBol_FileFound = True
lStr_CheckFile = IIf((rBol_FindAll = True), Dir, ""

Else
lStr_CheckFile = Dir
End If
End If
End If
End If
Wend
If ((lBol_FileFound = False) Or (rBol_FindAll = True)) Then
lInt_Idx = 1
While (lInt_Idx <= lCol_SubDirs.Count)
lBol_FileFound = FindFiles(rCol_FileList, lCol_SubDirs.Item(lInt_Idx), rStr_Pattern, rBol_FindAll)
If ((lBol_FileFound = False) Or (rBol_FindAll = True)) Then
lInt_Idx = lInt_Idx + 1
Else
lInt_Idx = lCol_SubDirs.Count + 1
End If
Wend
End If
FindFiles = lBol_FileFound
End Function
Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein