
Filename wildcards as arguments to script
You can not evaluate a wildcard statement for existence. However you can
check the base folder.
This sample will do:
====================================
Dim fso, FilesPath, BaseFolder, OK
If WScript.Arguments.count = 0 Then Call HowTo(1)
Set fso = CreateObject("Scripting.FileSystemObject")
FilesPath = WScript.Arguments(0)
Select Case Instr(FilesPath, "*")
Case 0 : If fso.FileExists(FilesPath) then OK = True
Case Else
BaseFolder = fso.GetParentFolderName(FilesPath)
If fso.FolderExists(BaseFolder) Then OK = True
End select
If OK then Wscript.Echo FilesPath Else: Call HowTo(2)
'..
'..
Sub HowTo (error)
Select Case error
Case 1
Wscript.Echo "Argument is missing. Error: " & error
Case 2
Wscript.Echo "Path to the File(s) is Invalid. Error: " & error
'..
'..
End Select
Wscript.Echo "Syntax: vbscript.vbs [valid_path]"
Wscript.Quit error
End Sub
=====================================
-regards-
Gurgen Alaverdian
http://www.gurgensvbstuff.com
Quote:
> Greetings...
> Anyone know if its possible/howto use filename-wildcards when calling my
> script ?
> To be more specific - I want to execute the script as "myVBScript
> c:\temp\*.*" - and then do something with the files/dirs afterwards (in
> fact, calling another program with a oshell.Run and then pass the argument
> on to this) - this could be hundreds of files and directories, so i dont
> just want to add more arguments.
> The argument part of my script looks like this :
> If WScript.Arguments.count = 0 Then
> Call HowTo
> Else
> Set oShell = CreateObject("Scripting.FileSystemObject")
> If (oShell.FileExists(WScript.Arguments(0))) Then Filename =
> WScript.Arguments(0)
> End If
> Any hints/suggestions welcome, perhaps it's just me who's thinking in
wrong
> terms :-)