File search problem

A

Anthony

I am using filesearch on a command button to search for a
specific file. The code below works but will return a
count of all files where any part of the file name matches
the search name. I would like the code to search for the
specific file only and return the search results for the
specific file.

Thanks for your help
Anthony


Set fs = Application.FileSearch

With fs
.NewSearch
.LookIn = "C:\download"
.MatchTextExactly = True
.FileName = "HFDWORKREQ.txt"

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 "TRANSFER FILE BEFORE YOU CONTINUE."
End If
End With
 
C

Chadlon

Hi Anthony,

Another route, given your statement of requirements, would be

pth$ = "C:\download\HFDWORKREQ.txt"
fnm$ = Dir(pth$)
if fnm$ <> "" Then
' file exists, so do whatever with it
' fnm is returned as (only) the file name, i.e. "HFDWORKREQ.txt"
Else
' file does not exist (in that folder)
End If

If you are trying to access a specific file in a known folder, Dir is
probably the way to go.

CD
 
G

Guest

This workes great thanks
Anthony
-----Original Message-----
Hi Anthony,

Another route, given your statement of requirements, would be

pth$ = "C:\download\HFDWORKREQ.txt"
fnm$ = Dir(pth$)
if fnm$ <> "" Then
' file exists, so do whatever with it
' fnm is returned as (only) the file name, i.e. "HFDWORKREQ.txt"
Else
' file does not exist (in that folder)
End If

If you are trying to access a specific file in a known folder, Dir is
probably the way to go.

CD




.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top