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

fso.FileExists method and joker char * 1

Status
Not open for further replies.

Targol

Technical User
Sep 13, 2002
908
FR
I had the (bad) surprise to see that the fso.fileExists method doesn't allow joker chars like "*".
ie :
Code:
fso.FileExists("c:\windows\System32\*.dll")
returns "false" even if "c:\windows\System32\" folder is full of dlls.
Does anyone know how to achieve this in an HTML included VBS ?

Any help would be apreciated. Water is not bad as long as it stays out human body ;-)
 
How about something like this?
Warning: On the fly and probably only conceptual rather than executable :)
Code:
Function checkForExtension(folderName, ext)
   Dim fso, fol, fil
   Dim cnt

   Set fso = Server.CreateObject("Scripting.FileSystemObject")
   Set fol = fso.getFolder(folderName)
   For each fil in fol
      if(right(fil.name,len(ext)) = ext) cnt = cnt + 1
   Next
   checkForExtension = cnt

   Set fol = Nothing
   Set fso = Nothing
End Function

That would return the number of files meeting a specifed extension in a specified directory, or 0 if none were matched. You could also set this up to return an array of matching filenames, and just do a UBound on the returned array to see if it has any contents.

-Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
 
Well, Tarwn, I think this'll do the stuff (may be not very optimized but I don't need to run it many times so that'll be good)
I give you a star for having search for me !!! Water is not bad as long as it stays out human body ;-)
 
Heres a much better one, I didn't think of full wildcard searching otherwise I might have written it myself :)

It uses regular expressions to test the file names and lets you use * or ? as valid wildcards anywhere in the string.

Wish I had thought to do actual wildcards instead of just extensions :p ah well, drink more coffee, write more code...

-Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top