Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get the exactly result with Application.FileSearch problem

Status
Not open for further replies.

softlover

Programmer
Apr 4, 2002
88
CN
I use Application.FileSearch codes to find a file in any folder. But the result isn't exactly. See following codes.
With Application.FileSearch
.LookIn = StrDirName
.filename = StrFileName
If .Execute() <= 0 Then
SeekFilesInDir = False
Exit Function
End If
SeekFilesInDir = True
End With
The problem is: I want to search the the file "ABC.txt". But if "ABC123.txt" or " or other files which name includes the "ABC" string in this folder. The returned variable "SeekFilesInDir" should be "TRUE".
Is there any good codes can solve the problem?
 
How are ya softlover . . . . .

just need to zero in a bit more. Try this:
Code:
[blue]   With Application.FileSearch
      [purple][b].NewSearch[/b][/purple]
      .LookIn = StrDirName
      .FileName = StrFileName
      [purple][b].MatchTextExactly[/b][/purple]
      
      If .Execute() > 0 Then
         SeekFilesInDir = True
      Else
         SeekFilesInDir = False
      End If
 
   End With[/blue]

Calvin.gif
See Ya! . . . . . .
 
Thanks to TheAceMan1.
The codes you mentioned also can't get the exactly result.
Now I use another codes for search file in any folder.
Private Function SeekFilesInDir(StrPath As String, Optional LngType As Long) As Boolean
On Error Resume Next
SeekFilesInDir = Len(Dir(StrPath, LngType)) > 0
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top