Classic ASP: All files containing 123 in filename

Using old classic ASP, how can I find all files containing "123" in their filename?  This returns all files:
  Dim strPathInfo, strPhysicalPath
  strPathInfo = Request.ServerVariables("PATH_INFO")
  strPhysicalPath = Server.MapPath(strPathInfo)
  Dim objFSO, objFile, objFileItem, objFolder, objFolderContents
  Set objFSO = CreateObject("Scripting.FileSystemObject")
  Set objFile = objFSO.GetFile(strPhysicalPath)
  Set objFolder = objFile.ParentFolder
  Set objFolderContents = objFolder.Files

  For Each objFileItem In objFolderContents
    Response.Write objFileItem.Name 


Open in new window

LVL 10
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Paul MacDonaldDirector, Information SystemsCommented:
  For Each objFileItem In objFolderContents
    IF INSTR(objFileItem.Name, "123") THEN
      Response.Write objFileItem.Name
skijAuthor Commented:
Using "IF" seems like a waste of resources because it would have to go through about a thousand files looking for a match.  In PHP I would use glob() for this:

Is there a similar way to do this in classic ASP?
Dave BaldwinFixer of ProblemsCommented:
glob() does the same thing as the ASP 'IF', you just don't have to see the details in your code.  The resources used are essentially the same.
You are already going through about a thousand files already by the simple fact that you are using a foreach in order to loop through all of the files in the directory (parent folder) of the selected file.  The if statement is required because you want to filter on files that contain "123" in their name.

Unfortunately, the Files collection object, of the FileSystemObject, does not contain such a method that accepts a filter.  .NET, on the other hand, does allow for filtering the contents of a directory listing.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.