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!

Finding a file using a wildcard 2

Status
Not open for further replies.
Nov 29, 2001
72
US
I am working on a company Intranet and I need to be able to retrieve a file name, which is a *.htm file, for display using VBScript.

I will have the entire directory path, but will not know the exact name of the htm file within that directory to display. In VB, one can use the "Dir" function to retrieve file names using wildcards, but there is no such function when using VBScript???

Appreciate any help offered,
Dave McReynolds
 
Code:
Function GetWildFile(strFolder, strWild) 
Dim objfs 
Dim objFolder
dim objFiles
Dim objFile
Dim strDesc
Set objfs = Server.CreateObject("Scripting.FileSystemObject")
On error resume next ' Intercept No Folder
    Set objFolder = objFS.GetFolder(strFolder)
    if Err.Number <> 0 then strDesc = Err.Description
On error goto 0
If Len(strDesc) = 0 then
     Set objFiles = objFolder.Files
     For Each objFile in ObjFiles
         if objFile.Name Like strWild then
             GetWildFile = objFile.Name
             Exit For
         End if
    Next
End if

Compare Code (Text)
Generate Sort in VB or VBScript
 
Dude,
I never thought a reply would be so quick in coming. I will use your function.

Thanks again and I gave you a star,
Dave
 
CatmanDave & John,

I noticed in your code you have:

&quot;if objFile.Name Like strWild then&quot;

Is &quot;Like&quot; a VBScript comparison method? I couldn't find that unless it's undocumented or new.

You might use:

If instr(1,objFile.Name, strWild, 1) > 0 then


fengshui_1998
 
fengshui_1998,
You were right although it worked without the second &quot;1&quot; parameter: If instr(1,objFile.Name, strWild) > 0 then

Thanks fengshui and John for your help,
Dave
 
catmandave,

The second one &quot;1&quot;, I believe, ignores upper or lower case.

fengshui_1998
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top