.FileName Property

ZMAN2

Registered User.
Local time
Yesterday, 23:06
Joined
May 6, 2003
Messages
37
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! :)
 
Yeah, I saw this post while doing a search, but the process that I am working on will have no user intervention to pick and choose which files to keep. Thanks for your help.
 
user input not needed the code is checking for a name match in the loop

'loop thru files returned by fs, and keep the one that matches
For Each varLoop in .FoundFiles
If cstr(varLoop) = fileName then

'Do Your thing here
End if
Next varLoop

Peter
 
Gotcha! I'll give it a try. Thanks again for all your help.
 

Users who are viewing this thread

Back
Top Bottom