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

Find files by mask

Status
Not open for further replies.

Skippi

MIS
Aug 7, 2004
19
CZ
I need a VBS script with 2 parameters (path name and mask), which for example display list of files according to path and mask. Path can be in UNC and mask can use "*" or "?" wildcards:
script.vbs C:\TEMP *.tmp
script.vbs \\Server\Share\Dir ????161.lst
Anybody have an idea ?
 
A starting point:
Set objArgs = WScript.Arguments
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "%COMSPEC% /C dir """ & objArgs(0) & "\" & objArgs(1) & """ & pause", 3, True

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I need to display list of files (better with date and size). I found solution using internal DIR command (see part below), but I would prefer "clear VBS" solution. I don't know how to test that any file exist. Script may run under many locals (English, Czech, French, ...) so I can not test string "File not found".

Const ForReading = 1
Const TemporaryFolder = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")

strSourceFile = strSourcePath & strFileMask

Call EchoTime("List of files " & strSourceFile & " :")

Set objTEMPDir = objFSO.GetSpecialFolder(TemporaryFolder)
strTEMPFile = objFSO.GetTempName
strTEMPFile = objTEMPDir.Path & "\" & strTEMPFile

' List files using redirestion to temporary file
' /U = create file in UNICODE
objShell.Run "cmd /U /C dir " & strSourceFile & " > " & strTEMPFile, 2, True

' Copy output to stdOutput
' False = dont't create when does not exist
' vbTrue = open in UNICODE
Set objTEMPFile = objFSO.OpenTextFile(strTEMPFile, ForReading, False, vbTrue)
WScript.Echo objTEMPFile.ReadAll
objTEMPFile.Close

I used CMD because I know, that this script will run under W2K or W2K3.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top