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 (that is, * or ?).
Practical Usage
Used to execute conditional steps based on the state of a file.
Parameters
General
Property | Type | Required | Default | Markup | Description |
---|---|---|---|---|---|
If | Text | Yes | File exists |
| Specifies the type
of evaluation to be performed. The available options are:
|
File | Text | Yes | (Empty) |
| 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) | 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 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 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 (|) (for 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
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.
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:
|
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).
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.
- Parameters containing user credentials, files, file paths, and/or other information specific to the task must be customized before the sample code can run successfully.
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.
<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" />