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" />

Related Topics   

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 (that is, * 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, by default, any If activity added to the Task Builder's Steps panel is always followed by an End If activity.

Practical usage

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

Parameters

General

 
PropertyTypeRequiredDefaultMarkupDescription
IfTextYesFile exists
  • ACTION="exist"
  • ACTION="not_exist"
  • ACTION="accessible"
  • ACTION="not_accessible"
Specifies the type of evaluation to be performed. The available options are:
  • File exists - 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 (that is, in use by another application).
  • File is not accessible - Results to TRUE if the file exists and currently inaccessible (in a locked state).
FileTextYes(Empty)
  • FILE="c:\folder\fileA.txt"
  • FILE="c:\folder\*.txt"
Indicates the full path and file name of the file in which to evaluate. wildcard characters (that is, * or ?) are supported. For example, to specify all text files, enter "c:\folder\*.txt".
Create and populate dataset with result information (optional)TextNo(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

 
PropertyTypeRequiredDefaultMarkupDescription
Include subfoldersYes/NoNoNoSUBFOLDERS="YES"If selected, denotes that, if present, subfolders should be searched for files matching the mask specified in the File parameter. If disabled (default), subfolders are ignored.
Exclude MaskTextNo(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 (|) (for example, "*.txt|*.bak").
Only if newer thanDateNo(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 thanDateNo(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

 
PropertyTypeRequiredDefaultMarkupDescription
AttributesText (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. 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

Error Causes

On Error

Additional notes

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).

 
NameData TypeReturn Value
theDataset.NameTextThe name of the file.
theDataset.SizeNumberThe size of the file.
theDataset.CreatedOnDateThe file creation date.
theDataset.ModifiedOnDateThe date the file was last modified.
theDataset.AccessedOnDateThe date the file was last accessed.
theDataset.IsFolderYes/NoWhether the file is a folder.
theDataset.IsReadOnlyYes/NoWhether the file's attribute is Read Only.
theDataset.IsArchiveYes/NoWhether the file's attribute is Archive.
theDataset.IsSystemYes/NoWhether the file's attribute is System.
theDataset.HiddenYes/NoWhether the file's attribute is Hidden.
theDataset.IsCompressedYes/NoWhether the file is compressed.
theDataset.IsAccessibleYes/NoWhether the file is accessible.

Example

NOTE:
  • Copy and paste the sample AML code below directly into the Task Builder Steps Panel.
  • To successfully run the sample code, update parameters containing user credentials, files, file paths, or other information specific to the task to match your environment.

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 file name.

Copy
<AMIF ACTIVITY="file_exist" FILE="c:\foldername\filename.txt"><AMSHOWDIALOG MESSAGE="The file exists." /></AMIF>
<AMSHOWDIALOG MESSAGE="The file exists." />
<AMIF ACTIVITY="end" />
<AMIF ACTIVITY="file_exist" FILE="c:\foldername\filename.txt" MODE="accessible"><AMSPEAK>The file is accessible.</AMSPEAK></AMIF>
<AMSPEECH TEXT="The file is accessible." VOLUME="100" SPEED="50" />
<AMIF ACTIVITY="end" />