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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

search folder for files using wildcards 1

Status
Not open for further replies.

charlotte49er

Programmer
Nov 17, 2001
25
US
Has anyone run across a way of searching a folder for files using a wildcard? I have a directory with several files with the same base name but different extensions. What I would like to be able to do is create an array of the files with the same base name without looping through all of the files in the directory. Thanks.
 
something like this should do it...

Code:
<HTML><BODY>
<B>Search Results for <%=Request("SearchText")%></B><BR>

<%
Const fsoForReading = 1

Dim strSearchText
strSearchText = Request("SearchText")

'Now, we want to search all of the files
Dim objFSO
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")


Dim objFolder
Set objFolder = objFSO.GetFolder(Server.MapPath("/"))

Dim objFile, objTextStream, strFileContents, bolFileFound
bolFileFound = False

For Each objFile in objFolder.Files
  If Response.IsClientConnected then
    Set objTextStream = objFSO.OpenTextFile(objFile.Path,fsoForReading)

    strFileContents = objTextStream.ReadAll

    If InStr(1,strFileContents,strSearchText,1) then
       Response.Write "<LI><A HREF=""/" & objFile.Name & _
                      """>" & objFile.Name & "</A><BR>"

       bolFileFound = True
    End If

    objTextStream.Close
  End If
Next

if Not bolFileFound then Response.Write "No matches found..."

Set objTextStream = Nothing
Set objFolder = Nothing
Set objFSO = Nothing
%>

</BODY></HTML>

-DNG
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top