WatchDirectory home page
WatchDirectory Startseite (Deutsche Version)
Site WatchDirectory (Français)
  Welcome, Guest. Please Login or Register
YaBB - Yet another Bulletin Board
   
  HomeHelpSearchLoginRegister  
 
Page Index Toggle Pages: 1
Using variables? (Read 1426 times)
Cherry
YaBB Newbies
*
Offline



Posts: 5
Using variables?
Oct 5th, 2016 at 11:27am
 
Newbie question:

I would like to monitor certain folder. e.g. c:\data files or \\servername\folder

I would prefer to do watching and actions with one Watchdirectory task. When new file appears to watched folder, Watchdirectory executes similarly named .bat or .cmd patch depending on the name of the file.

data1.dat ->data1.cmd
data2.dat ->data2.cmd
etc.

It should also archieve files to another folder after they are processed.

This should be easy, but I do not understand how variables are used in Watchdirectory.
Back to top
 
 
IP Logged
 
Gert
YaBB Administrator
*****
Offline



Posts: 2239
The Netherlands
Re: Using variables?
Reply #1 - Oct 5th, 2016 at 11:52am
 
Is that you Kari?

Yesterday I replied to an email:

I have written a little example script (attached) that you can use with "Run a bat file". If you know a little bit of bat scripting it should be easy enough to understand/change.

Here is the example script
Code:
rem where are all bat scripts located?
SET SCRIPTDIR=C:\Scripts

rem depending on the name of the detected file, call another script with that name
rem for example, when company1.Dat is detected call C:\Scripts\Company1.Bat
rem see http://www.watchdirectory.net/wdhelp/plugins/wdopAutoRunBatEnv.html for all WD_... variables
SET SCRIPTTOCALL=%SCRIPTDIR%\%WD_FILE_B%.bat

rem check if the script exist
IF NOT EXIST "%SCRIPTTOCALL% GOTO :NoScript

Call "%SCRIPTTOCALL%"
GOTO :EOF

:NoScript
rem do something here if the script does not exist...
 

Back to top
 

Gert Rijs - gert (at) gdpsoftware (dot) com
Blog: http://blog-en.gdpsoftware.com/
End Alzheimer's: http://www.alz.org&&...
WWW WWW GdPSoftware  
IP Logged
 
Cherry
YaBB Newbies
*
Offline



Posts: 5
Re: Using variables?
Reply #2 - Oct 5th, 2016 at 1:56pm
 
Gert wrote on Oct 5th, 2016 at 11:52am:
Is that you Kari?

Yesterday I replied to an email:

I have written a little example script (attached) that you can use with "Run a bat file". If you know a little bit of bat scripting it should be easy enough to understand/change.

Here is the example script
Code:
rem where are all bat scripts located?
SET SCRIPTDIR=C:\Scripts

rem depending on the name of the detected file, call another script with that name
rem for example, when company1.Dat is detected call C:\Scripts\Company1.Bat
rem see http://www.watchdirectory.net/wdhelp/plugins/wdopAutoRunBatEnv.html for all WD_... variables
SET SCRIPTTOCALL=%SCRIPTDIR%\%WD_FILE_B%.bat

rem check if the script exist
IF NOT EXIST "%SCRIPTTOCALL% GOTO :NoScript

Call "%SCRIPTTOCALL%"
GOTO :EOF

:NoScript
rem do something here if the script does not exist...
 




Yeah, it is me  Smiley I did not get your email. I checked clutter (junk) too, but it was not there. Could you resend it if it has more than in above?
Back to top
 
 
IP Logged
 
Cherry
YaBB Newbies
*
Offline



Posts: 5
Re: Using variables?
Reply #3 - Oct 5th, 2016 at 2:58pm
 
Can I use UNC paths in set scriptdirectory?

for example
SET SCRIPTDIR=\\servername\watchdirectory tasks
Back to top
 
 
IP Logged
 
Gert
YaBB Administrator
*****
Offline



Posts: 2239
The Netherlands
Re: Using variables?
Reply #4 - Oct 6th, 2016 at 7:43am
 
I would not advise it.
But if you do, you must make sure the scriptdir is available to the task. If your task runs as a windows service, network directories are typically not available. See http://blog-en.gdpsoftware.com/2010/04/watchdirectory-tasks-as-windows-service.h...
Back to top
 

Gert Rijs - gert (at) gdpsoftware (dot) com
Blog: http://blog-en.gdpsoftware.com/
End Alzheimer's: http://www.alz.org&&...
WWW WWW GdPSoftware  
IP Logged
 
Cherry
YaBB Newbies
*
Offline



Posts: 5
Re: Using variables?
Reply #5 - Oct 19th, 2016 at 3:09pm
 
I am still doing something wrong. Here is the logfile. The script you kindly gave to me takes nicely name of the changed file to variable, but after that happens an error and I don't know what it is.

C:\Program Files (x86)\watchDirectory>GOTO :StartOfBat
C:\Program Files (x86)\watchDirectory>"C:\Program Files (x86)\watchDirectory\wdAnnotate.exe" info "Starting \\serverx\hfm_files_test$\EPM Maestro tasks\HFM data upload script.bat for event"

C:\Program Files (x86)\watchDirectory>Call "\\serverx\hfm_files_test$\EPM Maestro tasks\HFM data upload script.bat" FILEREN
C:\Program Files (x86)\watchDirectory>rem where are all bat scripts located?
C:\Program Files (x86)\watchDirectory>SET SCRIPTDIR=Y:\EPM Maestro tasks
C:\Program Files (x86)\watchDirectory>rem depending on the name of the detected file, call another script with that name
C:\Program Files (x86)\watchDirectory>rem for example, when company1.Dat is detected call C:\Scripts\Company1.Bat
C:\Program Files (x86)\watchDirectory>rem see http://www.watchdirectory.net/wdhelp/plugins/wdopAutoRunBatEnv.html for all WD_... variables
C:\Program Files (x86)\watchDirectory>SET SCRIPTTOCALL=Y:\EPM Maestro tasks\FI11_HFM_DATAFILE.bat
C:\Program Files (x86)\watchDirectory>rem check if the script exist
The syntax of the command is incorrect.

C:\Program Files (x86)\watchDirectory>IF NOT EXIST "Y:\EPM Maestro tasks\FI11_HFM_DATAFILE.bat GOTO :NoScript
Back to top
 
 
IP Logged
 
Gert
YaBB Administrator
*****
Offline



Posts: 2239
The Netherlands
Re: Using variables?
Reply #6 - Oct 20th, 2016 at 7:28am
 
There is an error in the main bat script:
Code:
rem check if the script exist
IF NOT EXIST "%SCRIPTTOCALL% GOTO :NoScript
 


It is missing a " so change it to
Code:
rem check if the script exist
IF NOT EXIST "%SCRIPTTOCALL%" GOTO :NoScript
 


Back to top
 

Gert Rijs - gert (at) gdpsoftware (dot) com
Blog: http://blog-en.gdpsoftware.com/
End Alzheimer's: http://www.alz.org&&...
WWW WWW GdPSoftware  
IP Logged
 
Cherry
YaBB Newbies
*
Offline



Posts: 5
Re: Using variables?
Reply #7 - Oct 25th, 2016 at 9:25am
 
Gert wrote on Oct 20th, 2016 at 7:28am:
There is an error in the main bat script:
Code:
rem check if the script exist
IF NOT EXIST "%SCRIPTTOCALL% GOTO :NoScript
 


It is missing a " so change it to
Code:
rem check if the script exist
IF NOT EXIST "%SCRIPTTOCALL%" GOTO :NoScript
 




Got it! Too easy  Cheesy

Now to the next problem. Do I need to delete or move the file after the script executed has been finished? Otherwise Watchdirectory starts the loop from the beginning eternally. I would rather leave the monitored files in where they are and next version of the files just overwrite the old ones (and change of the file wiould trigger watchdirectory again).
Back to top
 
 
IP Logged
 
Gert
YaBB Administrator
*****
Offline



Posts: 2239
The Netherlands
Re: Using variables?
Reply #8 - Oct 26th, 2016 at 7:28am
 
You can leave the files there. However, in that case I would change the "Monitoring Method" to "File Age" and let it detect files "older than 1 minute". Make sure you check the option to "Remember triggered files". For "Events" select "FILENEW" and "FILECHNG".
Back to top
 

Gert Rijs - gert (at) gdpsoftware (dot) com
Blog: http://blog-en.gdpsoftware.com/
End Alzheimer's: http://www.alz.org&&...
WWW WWW GdPSoftware  
IP Logged
 
Page Index Toggle Pages: 1