Code: Select all
Option Explicit
dim objArgs
dim filename
dim folder
dim myRegExp
set myRegExp = New RegExp
myRegExp.IgnoreCase = False 'no need
myRegExp.Global = False 'replace once only
myRegExp.Pattern = "\\[^\\]*$" 'match everything from the last \ to the end of the string
dim WshShell
Function ExecuteWithTerminalOutput(cmd)
Set WshShell = WScript.CreateObject("WScript.Shell")
'use this line to hide the window, and wait until the new process finishes
'useful for debugging
WshShell.Run cmd, 1, true
'use this line below when debugging is not needed
' WshShell.Run cmd,0
ExecuteWithTerminalOutput = 0
End Function
'Set a reference to the arguments
Set objArgs = Wscript.Arguments
for each filename in objArgs
MsgBox "debug: filename= " & filename, vbOk
folder = myRegExp.replace( filename, "")
MsgBox "debug: folder= " & folder, vbOk
'decide which action to perform
if folder = "S:\AOS\PSD\SIMT\DFAS-Rpts\Comp Time Rpt" then
ExecuteWithTerminalOutput( "C:\WINDOWS\system32\cmd.exe /c S:\ISMS\DESOM\Xpedite\P6602R05.bat " + chr(34) + filename + chr(34) )
elseif folder = "S:\AOS\PSD\SIMT\DFAS-Rpts\COHRPT" then
ExecuteWithTerminalOutput( "C:\WINDOWS\system32\cmd.exe /c S:\ISMS\DESOM\Xpedite\P6607RC1.bat " + chr(34) + filename + chr(34) )
elseif folder = "S:\AOS\PSD\SIMT\DFAS-Rpts\RETRO" then
ExecuteWithTerminalOutput( "C:\WINDOWS\system32\cmd.exe /c S:\ISMS\DESOM\Xpedite\P6608RC1.bat " + chr(34) + filename + chr(34) )
else
MsgBox "Unknown action for file " & filename & " in folder " & folder, vbOk
end if
'note - this loop is only required if you want to wait for the batch files to end
next
Set WshShell = Nothing
Set myRegExp = Nothing
Set objArgs = Nothing
Parameters: <full path\>new_action_per_folder.vbs %FILE%