If - File Exists

Declaration

<AMIF ACTIVITY="file_exist" FILE="text" MODE="text (options)" 
RESULTDATASET="text" SUBFOLDERS="yes/no" 
EXCLUDE="text" RE="yes/no" ISNEWERTHAN="date serial" ISOLDERTHAN="%date serial">

Description: Determines the existence of a file and returns TRUE or FALSE depending on the outcome.If the result evaluates to TRUE, the task will execute the block of steps immediately following this step up until an End if step is encountered. If the result evaluates to FALSE, the block will be skipped and execution will proceed directly after the End if step (or if an Else step is encountered, the task will execute that block of steps instead, up until an End if step is encountered). This activity supports wildcard characters (e.g., * or ?).

NOTE: All If activities must be followed at some point with an End if step to mark the end of the code block that is to be executed if the expression is true. For ease of use, any If activity added to the Steps pane of the task builder is always followed by an End if activity.

Practical Usage

Used to execute conditional steps based on the state of a file.

General Parameters

Property Type Required Default

Markup

Description

If

Text

Yes

Exists

  1. ACTION="exist"

  2. ACTION="not_exist"

  3. ACTION="accessible"

  4. ACTION="not_accessible"

Specifies the type of evaluation to be performed. The available options are:

  • File exists (default) - Results to TRUE if the file exists.

  • File does not exist - Results to TRUE if the file does not exist.

  • File is accessible - Results to TRUE if the file exists and is currently accessible. Accessible meaning not in a locked state (e.g., in use by another application).

  • File is not accessible - Results to TRUE if the file exists and currently inaccessible (in a locked state).

File

Text

Yes

(Empty)

  1. FILE="c:\folder\fileA.txt"

  2. FILE="c:\folder\*.txt"

Indicates the full path and filename of the file(s) in which to evaluate. Wildcard characters * or ? are supported. For example, to specify all text files, enter "c:\folder\*.txt."

Create and populate dataset with result information (optional)

Text

No

(Empty)

RESULTDATASET="theData"

The name of the dataset to create and populate with information about the file that caused the If block to be executed. The table below (under Datasets) describes the set of fields that this dataset creates.

File Options

Property

Type

Required

Default

Markup

Description

Include subfolders

Yes/No

No

No

SUBFOLDERS="yes"

If set to YES, denotes that, if present, subfolders should be searched for files matching the mask specified in the File parameter. If set to NO (default), subfolders are ignored.

Exclude Mask

Text

No

(Empty)

EXCLUDE="*.txt"

Causes this activity to omit files matching the mask specified. File names or wildcard masks may be used. Multiple entries may be specified by separating them with a pipe symbol (|). Example: *.txt|*.bak

Only if newer than

Date

No

(Empty)

ISNEWERTHAN=

"%DateSerial(2007,02,01) + TimeSerial(00,00,00)%"

Causes this activity to evaluate only files newer than the date/time specified. If this parameter is left blank or not included, the file date will be ignored.

Only if older than

Date

No

(Empty)

ISOLDERTHAN=

"%DateSerial(2007,02,01) + TimeSerial(00,00,00)%"

Causes this activity to evaluate only files older than the date/time specified. If this parameter is left blank or not included, the file date will be ignored.

File Filter Parameters

Property

Type

Required

Default

Markup

Description

Attributes

Text (options)

No

(Empty)

ATTRFILTER="+R+A-H" (compress read-only & archive files but not hidden files)

This group of settings causes the activity to filter which files to look for based on the attribute settings of the source file(s). In visual mode, a group of controls are provided to assist in the selection of this parameter. In markup mode, a single text item must be specified that contains the attributes of the files you wish to look for. Available options are:

  • R—Read-only: Specifying "+R" causes files with this attribute turned on to be included, "-R" causes files with this attribute turned off to be included, not specifying the letter (default) causes this attribute to be ignored.

  • A—Archive: Specifying "+A" causes files with this attribute turned on to be included, "-A" causes files with this attribute turned off to be included, not specifying the letter (default) causes this attribute to be ignored.

  • S—System: Specifying "+S" causes files with this attribute turned on to be included, "-S" causes files with this attribute turned off to be included, not specifying the letter (default) causes this attribute to be ignored.

  • H—Hidden: Specifying "+R" causes files with this attribute turned on to be included, "-H" causes files with this attribute turned off to be included, not specifying the letter (default) causes this attribute to be ignored.

  • C—Compression: Specifying "+C" causes files with this attribute turned on to be included, "-C" causes files with this attribute turned off to be included, not specifying the letter (default) causes this attribute to be ignored.

Description tab - A custom description can be provided on the Description tab to convey additional information or share special notes about a task step.

Error Causes tab - Specify how this step should behave upon the occurrence of an error. (Refer to Task Builder > Error Causes Tab for details.)

On Error tab - Specify what AWE should do if this step encounters an error as defined on the Error Causes tab. (Refer to Task Builder > On Error Tab for details.)

Datasets

A dataset is a multiple column, multiple row container object. This activity creates and populates a dataset containing a specific set of fields. The table below describes these fields (assuming the dataset name assigned was theDataset).

Name

Data Type

Return Value

theDataset.Name

Text

The name of the file.

theDataset.Size

Number

The size of the file.

theDataset.CreatedOn

Date

The file creation date.

theDataset.ModifiedOn

Date

The date the file was last modified.

theDataset.AccessedOn

Date

The date the file was last accessed.

theDataset.IsFolder

Yes/No

Whether the file is a folder.

theDataset.IsReadOnly

Yes/No

Whether the file's attribute is Read Only.

theDataset.IsArchive

Yes/No

Whether the file's attribute is Archive.

theDataset.IsSystem

Yes/No

Whether the file's attribute is System.

theDataset.Hidden

Yes/No

Whether the file's attribute is Hidden.

theDataset.IsCompressed

Yes/No

Whether the file is compressed.

theDataset.IsAccessible

Yes/No

Whether the file is accessible.

Example

The sample AML code below can be copied and pasted directly into the Steps panel of the Task Builder.

Description This sample task checks if "c:\foldername\filename.txt" exists. If so, a Message Box activity displays the message "The file exists". The task then checks if the same file is currently accessible. If so, a Speak activity speaks the message "The file is accessible". To make sure this task works properly, point the If file exists steps to a valid filename.

<AMIF ACTIVITY="file_exist" FILE="c:\foldername\filename.txt">
<AMSHOWDIALOG MESSAGE="The file exists." />
</AMIF>
<AMIF ACTIVITY="file_exist" FILE="c:\foldername\filename.txt" 
 MODE="accessible">
<AMSPEAK>The file is accessible.</AMSPEAK>
</AMIF>