I have used this code many times to find multiple files in a directory, but how do you look for a single file. My dilema, I have 2 files in a directory:
File #1: filename.txt
File #2: filename_date.txt
If I use the .FileName = "filename.txt" it still returns both files???? Is there another method used for this purpose?
Set fs = Application.FileSearch
With fs
.LookIn = "C:\My Documents"
.FileName = "cmd*.*"
If .Execute > 0 Then
MsgBox "There were " & .FoundFiles.Count & _
" file(s) found."
For i = 1 To .FoundFiles.Count
MsgBox .FoundFiles(i)
Next i
Else
MsgBox "There were no files found."
End If
End With
Thanks again for all your help. Great forum!
File #1: filename.txt
File #2: filename_date.txt
If I use the .FileName = "filename.txt" it still returns both files???? Is there another method used for this purpose?
Set fs = Application.FileSearch
With fs
.LookIn = "C:\My Documents"
.FileName = "cmd*.*"
If .Execute > 0 Then
MsgBox "There were " & .FoundFiles.Count & _
" file(s) found."
For i = 1 To .FoundFiles.Count
MsgBox .FoundFiles(i)
Next i
Else
MsgBox "There were no files found."
End If
End With
Thanks again for all your help. Great forum!