watchDirectory Help

Help Home
Creating New Tasks
Running Tasks
Task History

Plugins

Standard versus Pro
Version History

Search

See Also...




Free 30 day evaluation!
Standard version: $79 USD
Professional version: $149 USD
Buy Now!

 

German Helpfile

German Helpfile

French Helpfile

French Helpfile


Privacy Policy

Environment Variables

The variables below are available to the .bat file plugin, Run any Program plugin and the Email plugin.
Please note that the WD_Oxxx variables mentioned are only set when a "rename" event (FILEREN, DIRREN) is detected. The WD_Oxxx variables pertain to the original name of the file or directory. Rename events are only fired when you use the Fast monitoring method.

Variable NameApplicable to EventsNotesExample value/Usage
WD_REASONAll This variable contains the reason why your script was called. When its value is, for example, FILENEW it means your script is called because a new file is created inside the monitored directory.
FILENEW, FILEDEL, FILECHNG, FILEREN, DIRNEW, DIRDEL, DIRREN, QUIET
rem ignore changed file events
IF "%WD_REASON%" EQU "FILECHNG" GOTO :EOF
WD_DIRAll This variable contains the directory that is monitored by watchDirectory.
C:\Monitor Me
WD_FILE, WD_OFILE All, except "QUIET" This variable contains the complete name of the file or directory that caused the event.
C:\Monitor Me\SubDir\NewFile.txt
rem copy the new file
COPY "%WD_FILE%" X:\CopyDir
WD_FILE_D, WD_OFILE_D All, except "QUIET" This variable contains the name of the directory where the file or directory causing the event is located. This variable always ends with a backslash (\).
C:\Monitor Me\SubDir\
WD_FILE_N, WD_OFILE_N All, except "QUIET" This variable contains the name (without directory) of the file or directory causing the event.
NewFile.txt
rem copy the new file
COPY "%WD_FILE%" "X:\CopyDir\%WD_FILE_N%"
WD_FILE_B, WD_OFILE_B All, except "QUIET" This variable contains the name (without directory and extension) of the file or directory causing the event.
NewFile
rem copy the new file
COPY "%WD_FILE%" "X:\CopyDir\%WD_FILE_B%.OLD"
WD_FILE_E, WD_OFILE_E All, except "QUIET" This variable contains the file extension of the file or directory causing the event. This extension is always in capital letters and does not include the dot (.). This variable will be empty for files and directories without an extension.
TXT
rem ignore TXT files before 6 am
IF "%WD_FILE_E%%WD_TIME%" LSS "TXT060000" GOTO :EOF
WD_RELDIR, WD_ORELDIR All, except "QUIET" This variable contains the "relative directory" of the file causing the event. The relative directory is the path starting at the monitored directory. It will be empty for events directly inside the monitored directory.
SubDir
rem make sure the same dir exists below X:
MKDIR "X:\%WD_RELDIR%"
rem and copy the new file
COPY "%WD_FILE%" "X:\%WD_RELDIR%"
WD_FILE_SIZEFILENEW, FILECHNG, FILEREN This variable contains the size in bytes of this file.
1204
rem do not copy small files
IF %WD_FILE_SIZE% LEQ 1024 GOTO :IgnoreSmall
WD_FILE_SIZE_KBFILENEW, FILECHNG, FILEREN This variable contains the size in kilobytes of this file. It has the value of WD_FILE_SIZE divided by 1024. Files with a size smaller than 1024 bytes will have a WD_FILE_SIZE_KB value of 0.
64
rem do not copy files smaller than 1 MB
IF %WD_FILE_SIZE_KB% LEQ 1024 GOTO :IgnoreSmall
WD_FILE_SIZE_MBFILENEW, FILECHNG, FILEREN This variable contains the size in megabytes of this file. It has the value of WD_FILE_SIZE_KB divided by 1024. Files with a size smaller than 1024 kilobytes will have a WD_FILE_SIZE_MB value of 0.
10
rem do not copy files smaller than 1 MB
IF %WD_FILE_SIZE_MB% LEQ 1 GOTO :IgnoreSmall
WD_FILE_SIZE_GBFILENEW, FILECHNG, FILEREN This variable contains the size in gigabytes of this file. It has the value of WD_FILE_SIZE_MB divided by 1024. Files with a size smaller than 1024 megabytes will have a WD_FILE_SIZE_GB value of 0.
2
rem only copy files less than 1GB
IF %WD_FILE_SIZE_GB% EQ 0 GOTO :CopyThisFile
WD_FILE_DATE_CR, WD_FILE_TIME_CRFILENEW, FILECHNG, FILEREN These variables will have the creation date (YYYYMMDD) and time (HHMMSS) of the file.
20070131
REM change the date from YYYYMMDD format to MMDDYYYY format SET YYYY=%WD_FILE_DATE_CR:~0,4% SET MM=%WD_FILE_DATE_CR:~4,2% SET DD=%WD_FILE_DATE_CR:~6,2% SET MMDDYYYY=%MM%%DD%%YYYY%
WD_FILE_DATE_LM, WD_FILE_TIME_LMFILENEW, FILECHNG, FILEREN These variables will have the last modified date (YYYYMMDD) and time (HHMMSS) of the file.
20070131
WD_FILE_SHORTPATHFILENEW, FILECHNG, FILEREN, DIRNEW, DIRREN This variable contains the DOS 8.3 compatible name of the file or directory.
C:\MONI~001\SUBDIR\NEWF~001.TXT
WD_FILE_SHORTNAMEFILENEW, FILECHNG, FILEREN, DIRNEW, DIRREN This variable contains the DOS 8.3 compatible name without directory of the file or directory.
NEWF~001.TXT
WD_FILE_OWNERFILENEW, FILECHNG, FILEREN, DIRNEW, DIRREN This variable contains the name of the owner of the file or directory.
John
WD_INSTDIRAll This contains the directory where watchDirectory is installed.
C:\Program Files\watchDirectory
ANNOTATEAll This contains the complete path to the wdAnnotate.exe program. See using the wdAnnotate program for more info on the wdAnnotate program.
"C:\Program Files\watchDirectory\wdAnnotate.exe"
WD_TASKDIRAll This contains the directory in which your task information is stored.
C:\Documents and Settings\All Users\Application Data\watchDirectory\AutoCopy
WD_CONFIGAll This contains the name you assigned to the task.
AutoCopy
WD_CURRUNAll This variable contains the unique run number assigned to this task. The very first time you start a task, this run number will be 1.
Together with the WD_CUREVT and WD_CONFIG variables you can use it to construct a unique filename (without risking to overwrite other files).
117
rem create a temp file for processing
ECHO %WD_REASON% %WD_FILE% > C:\temp\%WD_CONFIG%_%WD_CURRUN%_%WD_CUREVT%.TMP
WD_CUREVTAll This variable contains the unique event number assigned to the current event. This event number is unique for all events of this task (also for multiple runs).
200
WD_EVENTNOAll

This variable contains a unique event number assigned to the current event. This event number is reset for each run (WD_CURRUN) of a task. The first event of a run will have WD_EVENTNO set to 1.

Important: This variable is only available for the .bat file plugin, not for the other plugins.

1
rem call a script only for the first event
IF %WD_EVENTNO% EQU 1 Call "C:\Scripts\FirstEvent.bat"
									
WD_DATEAll This variable contains the current date in the format YYYYMMDD.
20050714
rem write the event name and file to the log
ECHO %WD_REASON% %WD_FILE% >> C:\logs\log_%WD_DATE%.txt
WD_TIMEAll This variable contains the current time in the format HHMMSS (24 hour clock).
165959
rem write the time and file to the log
ECHO %WD_TIME% %WD_FILE% >> C:\logs\log_%WD_DATE%.txt
WD_DTTMAll This variable contains the current date and time in the format YYYYMMDD HHMMSS (24 hour clock).
20050714 165959
rem write the timestamp and file to the log
ECHO %WD_DTTM% %WD_FILE% >> C:\logs\log_%WD_DATE%.txt