Summary 

This article demonstrates how to use a script to filter files for File Conditions.

More Information

The File Trigger allows you to trigger adTempus jobs based on the creation, modification, or deletion of files. The basic File Trigger properties allow you to define which files should trigger the job using file names and basic wildcards, but do not provide any more advanced filtering settings, such as excluding certain files. However, the File Trigger allows you to provide a script that is executed for each potential trigger file. Using a script you can easily add additional filter criteria.

For example, suppose you want to trigger for all files created in the "c:\triggerfiles" directory except files with a ".bak" extension.

Steps

Begin by creating a File Trigger with the "Trigger when file is created" condition checked.

Next, in the Files section, click Add and add a new File Specification for "c:\triggerfiles\*.*". This will cause adTempus to examine every file created in the "triggerfiles" directory.

Next you will add a script to filter out files with the ".bak" extension. To do this

  1. Check the "Use a script to select files" option and click the Select button below it.
  2. In the Select Script window, click New to create a new script.
  3. The Script Properties window will appear.
  4. Make sure the Language is set to "VB.NET"
  5. In the script code editor at the bottom of the window, delete the template code that adTempus has inserted.
  6. Paste in the following script code:
Imports System  
Imports System.Collections  
Imports ArcanaDevelopment.adTempus.Server  
 
Public Class UserScript  
    Inherits ArcanaDevelopment.adTempus.ScriptEngine.UserScriptBase  
 
    Public Overrides Function Run() As Object 
      
        'The "FileName" variable is set by the trigger to the full path and name of the file  
        'that triggered the job.  
        'We use .NET file parsing capabilities to check the extension  
            If System.IO.Path.GetExtension(adTempus.JobVariables("FileName"))=".bak" Then 
                'Don't trigger for files with ".bak" extension  
                Return False 
            Else 
                'Trigger for all other extensions  
                Return True 
            End If 
    End Function 
End Class 
  1. Click OK three times to return to the Job Properties.
  2. Complete any additional configuration required for the job, and then save it.

How it Works

Each time adTempus encounters a file that meets the basic selection criteria (in this case, any time a file is created in the "c:\triggerfiles" directory), it runs your script, passing it information about the file that it found. It passes this information by setting values in the JobVariables collection.

Your script retrieves the name of the file and examines the file extension. If the extension is ".bak", the script returns "False", indicating that adTempus should not trigger the job. If the extension is not ".bak", the script returns "True", indicating that adTempus should trigger the job.

Extending the Filtering Functionality

In this example the script performed a simple task--examining the extension of the file. However, you can use the same technique to perform any other kind of filtering that you require, based on the file's properties or even its contents. For example, you could easily trigger only for files whose name matches a certain pattern, or read the file and trigger only for files that contain certain text.