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: 2164
Joined: Mon Jun 30, 2003 12:32 pm
Location: Melbourne, Australia
Contact:

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) )
           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 543 times
Regards,

Simon Carter, http://DataMystic.com/forums/index.php
http://PredictBGL.com - Insulin dose calculator for Type 1 diabetes
http://DownloadPipe.com - 250,000 free software downloads
http://DetachPipe.com - send huge email attachments

Return to “FileWatcher, DirDate and other Support”

Who is online

Users browsing this forum: Baidu [Spider] and 1 guest