Application.Filesearch with wildcards

R

Rich K

I'm using the application.filesearch to find files that have file path files
that fulfill certain text comparisons.
This is what my code looks like:

Dim vItem As Variant
Dim db As DAO.Database
Dim searchString As String
Dim searchLocation As String

searchString = Nz(Me.txtSearchString.Value, "")
searchString = Replace(searchString, "_", "[_]")
searchString = Replace(searchString, "#", "[#]")
searchLocation = Nz(Me.txtSearchLocation.Value, "")

Select Case Me.SearchType.Value
Case 1
searchString = searchString & "*"
Case 2
searchString = "*" & searchString
Case 3
searchString = "*" & searchString & "*"
Case Else
End Select

Set db = CurrentDb
With Application.FileSearch
.FileName = searchString
.LookIn = searchLocation
.MatchTextExactly = False
.SearchSubFolders = True
.Execute

For Each vItem In .FoundFiles
Me.lisFiles.AddItem vItem
Next vItem
End With
Set db = Nothing

-------------------------------------------------------------------
 

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