Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents

...

Directory Monitoring

...

Excerpt

JobScheduler can monitor file creation

, file change and timestamp change

with a (standalone) job and with an order (and a job chain).

In this article the directory monitoring using a standalone job is described.
For further information on how to use file watching with a job chain we recommend reading Directory Monitoring with File Orders.

This job can then start a job chain or job group.

An example how to configure a "file-watcher"configuration for monitoring a directory:

Code Block
languagehtml/xml
<job
&lt;job name = "scheduler_file_notification_1">
&lt;script<script language="shell">
&lt;<![CDATA[
                set
                echo %SCHEDULER_JOB_NAME%
                echo %SCHEDULER_TASK_TRIGGER_FILES%
                rem del %SCHEDULER_TASK_TRIGGER_FILES%
            ]]>
&lt;</script>
&lt;start<start_when_directory_changed directory = "c:/temp" regex = "^file[1|2]\.xml$"/>
&lt;</job>

This job will watch monitor the folder "c:/temp" on a ms-windows Windows® operating system. With the The regular expression one can define, what  is used to define which file(s) JobScheduler has JS to watch. In this example the regex means, that every event regarding the files "regular expression means that on a directory change (deleting, renaming, adding any file) the job will be startet when the files file1.xml" and/or "file2.xml" will fire the execution of the embedded script (in this case it will echo some values for JS-Environment Variables to stdout). is in content of the directory. 

The SCHEDULER_TASK_TRIGGER_FILES environment variable contains the names of all the files in the c:/temp folder that matches the regular expression at the time when the directory was changed- it does contain the name of the file that triggered the embedded script only in the case the file matches the regular expression. The file names are maintained in a semicolon separated list.

Note that this behaviour could be critical when two files (e.g. file1.xml and file2.xml) are created at the same time.

  • Two tasks will then be started for the job.
  • In the first task the environment variable SCHEDULER_TASK_TRIGGER_FILES will have the value c:/temp/file1.xml;c:/temp/file2.xml.
  • In the second task the environment variable SCHEDULER_TASK_TRIGGER_FILES will have a value that depends on what the first task has done with the files.
  • If, for example, the first task deletes the files in c:/temp then SCHEDULER_TASK_TRIGGER_FILES will be empty for the second task.

 

Set up as a standalone job in the JobScheduler Editor JOE the script will look like this:

Image Added


The directory settings and regular expression settings are entered in the 'FileWatcher' tab in JOE as follows:

Image Added

For further information on how to use file watching with a job chain we recommend reading Directory Monitoring with File Orders.

See also