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

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

FileWatcher .vbs Script for different action per folder

Postby DataMystic Support » Wed Jun 16, 2010 6:23 am

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) )
           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
Set WshShell = Nothing
Set myRegExp = Nothing
Set objArgs = Nothing

Command: C:\Windows\System32\wscript.exe
Parameters: <full path\>new_action_per_folder.vbs %FILE%
different action for each
(928 Bytes) Downloaded 548 times

Simon Carter, - Insulin dose calculator for Type 1 diabetes - 250,000 free software downloads - send huge email attachments

Return to “FileWatcher, DirDate and other Support”

Who is online

Users browsing this forum: No registered users and 1 guest