Purpose:Monitor folder and/or file creation, modification, and deletion

 

Format:FOLDERMONITOR [/C [folder]]

FOLDERMONITOR /Wn /S folder /I"file" /E"file" /U CREATED DELETED MODIFIED RENAMED n command

 

folderFolder (directory) or file name
CREATEDExecute the command if the folder or file is created
DELETEDExecute the command if the folder or file is deleted
MODIFIEDExecute the command if the folder or file is modified
RENAMEDExecute the command if the folder or file is renamed
nNumber of repetitions (or FOREVER)
commandCommand to execute when condition is triggered

 

/C(lear)/S(ubdirectories)
/E(xclude)/U(nlocked file)
/I(include)/W(ait)

 

Usage:

 

If you don't enter any arguments, FOLDERMONITOR will display the folders and files it is currently monitoring, in the format:

 

folder        (include/exclude)        condition        (n)        command

 

The command line will be parsed and expanded before FOLDERMONITOR is executed, so if you want to pass redirection characters or variables to command you will need to protect them (by enclosing in single back quotes, doubling the %'s, or using command grouping).

 

The MODIFIED condition is set if the file's size, attributes, or last access date and time are changed.

 

If you want to monitor multiple conditions for a file or folder, put them into a single FOLDERMONITOR command. FOLDERMONITOR creates a separate thread for each FOLDERMONITOR command, so if you have multiple commands you will be wasting CPU time, RAM, and risk having command executed simultaneously in different threads.

 

If the last argument on the line is a single (, it is interpreted as the beginning of a command group. FOLDERMONITOR will append the following lines (in a batch file) or prompt you for more input (at the command line) until it gets a closing ).

 

When the condition is triggered, the command will be executed immediately in the separate thread. This may cause problems if you try to write to the display or access files while the main TCC thread is also performing I/O. You may need to use START or DETACH in command to avoid conflicts.

 

FOLDERMONITOR creates several environment variables when a file or folder is created, deleted, modified, or renamed that can be queried by command. The variables are deleted after command is executed.

 

_folderactionThe type of change to the file or folder. The possible values are:

 

CREATED

DELETED

MODIFIED

RENAMED

 

_foldercountThe number of times the condition has been triggered

 

_foldernameThe name of the folder being monitored

 

_folderfile1The name of the file or folder that was created/deleted/modified/renamed. If the file was renamed, folderfile1 is the old name.

 

_folderfile2If a file was renamed, folderfile2 is the new name

 

_foldertimeSystem time when the change occurred.

 

For example, to monitor your d:\results directory and copy any new or modified files to a web page:

 

foldermonitor d:\results created modified forever copy "%%_folderfile1" "http://mycompany.com/results/"

 

Options:

 

/CIf name is specified, remove the monitor for that folder. Otherwise, remove all folder / file monitors. /C cannot be combined with any other options.

 

/EFilename to be excluded. If you want to exclude multiple files, use multiple /E options. If you want to exclude a file in a specific subdirectory,  the filename should include the relative path from the folder name. The name can include wildcards.

 

/IFilename to be included. If you want to include multiple files, use multiple /I options. If you want to include a file in a specific subdirectory, the filename should include the relative path from the folder name. The name can include wildcards.

 

/SInclude subdirectories.

 

/UDon't set the trigger until the file is unlocked. Not compatible with CREATED, because FOLDERMONITOR will always get the notification before the file is accessible.

 

/WnWait for n milliseconds before processing the file / directory change. This is useful if you have a lot of actions occurring in a short period and you only care about the last one. If you specify /Wn, it must be the first argument in the FOLDERMONITOR command.