FileWatcher .vbs Script for different action per folder

Discuss our other products here. Get help with installation and running, notify us of bugs, request new features and enhancements.

Moderators: DataMystic Support, Moderators, DataMystic Support, Moderators, DataMystic Support, Moderators

Post Reply
User avatar
DataMystic Support
Site Admin
Posts: 2227
Joined: Mon Jun 30, 2003 12:32 pm
Location: Melbourne, Australia
Contact:

FileWatcher .vbs Script for different action per folder

Post by DataMystic Support »

Save as new_action_per_folder.vbs

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
Command: C:\Windows\System32\wscript.exe
Parameters: <full path\>new_action_per_folder.vbs %FILE%
Attachments
different action for each folder.zip
(928 Bytes) Downloaded 3778 times
Post Reply