This code will scroll through all of the directories/sub-directories in the C Drive looking for a file call "myFile.TXT"
(This code uses the FileSystemObject so you will have to remember and reference the Microsoft Scripting Runtime library in your project.)
Code:
Dim m_objFSO As Scripting.FileSystemObject
Private Sub Command1_Click()
Set m_objFSO = New Scripting.FileSystemObject
Screen.MousePointer = vbHourglass
Call CheckFolder("C:\")
Screen.MousePointer = vbDefault
End Sub
Public Sub CheckFolder(sPath As String)
Dim objFolder As Scripting.Folder
Dim objSubDirs As Scripting.Folders
Dim objLoopFolder As Scripting.Folder
Dim myItem As String
Set objFolder = m_objFSO.GetFolder(sPath)
'Does the sPath string require an extra back-slash?
If Right(sPath, 1) <> "\" Then sPath = sPath & "\"
If (m_objFSO.FileExists(sPath & "myFile.TXT")) Then
msgbox "File exists in directory : " & sPath
End If
Set objSubDirs = objFolder.SubFolders
'Repeat this Sub for each sub directory in
'the SubFolders collection
For Each objLoopFolder In objSubDirs
CheckFolder objLoopFolder.Path
Next objLoopFolder
'Free up memory
Set objSubDirs = Nothing
Set objFolder = Nothing
End Sub
Hope this helps.