Get File(s) Information

Declaration

<AMGETFILEINFO FILE="text" RESULTVARIABLE="text" FILEPROPERTY="Text(options)" ISNEWERTHAN="date" />

See Also

Touch File, Copy File, Move File, Delete File, Delete Folder, Rename Folder, Write to File, Join File, Concatenate Files

Description

Retrieves information (i.e. File Name, Extension, Creation time, Modified time) regarding one or more files and stores the results into an AutoMate variable or dataset. To specify more than one file, use wildcard characters (i.e. * or ?). To specify multiple files or wildcard masks, separate them with a pipe symbol (i.e. c:\*.txt|c:\*.bak).

Practical Usage

Commonly used to gather data about one or more files and perform conditional actions depending on the information.

Parameters

General Properties

Property

Type

Required

Default

Markup

Description

Source

Text

Yes

(Empty)

a)SOURCE="c:\sourcefolder\file.txt"
b)SOURCE="c:\sourcefolder\*.txt"
c)SOURCE="c:\folder\*.txt|c:\folder\*bak"
d)SOURCE="filename.txt"

The file(s) in which information should be retrieved from. This can be a fully qualified path and file name (preferred) or a file name only (requires use of the Change Folder action). Wildcard characters (* or ?) may be used to specify files matching a certain mask. Multiple file and/or file masks may be specified by separating the entries with a pipe symbol (c:\*.txt|c:\*.bak).

Populate variable with result

Text

No

(Empty)

a)RESULTVARIABLE="theFileName.txt

b)RESULTVARIABLE="fileA.txt;fileB.txt"

If enabled, specifies the name of the variable to populate with the chosen file's information as specified in the File property parameter. If multiple files are specified, the variable will be populated with file property of each file separated by a semi colon. For example, if the file property selected is Filename, the variable will store information in this manner: fileA.txt;fileB.txt;fileC.txt, etc.

File Property

Text

No

Fullname

FILEPROPERTY="Size"

The file property in which to populate the variable with. This parameter is available only when the Populate variable with result parameter is enabled. The available options are:

  • Fullname - The full path and file name of the file (i.e. C:\Temp\FileName.txt)

  • Parent - The parent folder (i.e. C:\Temp)

  • Filename - The file name and extension, excluding path (i.e. FileName.txt)

  • Extension - The file's extension (i.e. .txt)

  • Size - The size of the file in KB (i.e. 1592)

  • IsReadOnly - Whether the file is Read Only (i.e. True or False)

  • CreationTime - The file's creation date/time (i.e. 3/20/2010 9:20:20 AM)

  • LastAccessTime - The date/time the file was last accessed (i.e. 3/20/2010 9:20:20 AM)

  • LastWriteTime - The date/time the file was last written to (i.e. 3/20/2010 9:20:20 AM)

  • Attribites - The file's attribute (i.e. Archive)

 

Dataset to populate

Text

No

(Empty)

RESULTDATASET="DatasetName"

If enabled, specifies the name of the dataset to populate with all available  information about one or more files. More details about the dataset that this action creates is entered below under Notes.

 

Options Properties

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 Source parameter. If set to NO (default value), subfolders are altogether ignored.

Exclude Mask

Text

No

(Empty)

EXCLUDE="*.txt"

Causes this action to omit files matching the mask(s) 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

Regular Expression

Yes/No

No

No

RE="YES"

If set to YES, specifies that the data entered in the Exclude Mask field is a regular expression.

Only if Newer Than

Date

No

(Empty)

ISNEWERTHAN=

"%DateSerial(2001,10,12) + TimeSerial(00,00,00)%"

Causes this action to only include files if the source is newer than the date/time specified. If this parameter is left blank or not included, the date of the files will be ignored.

Only if Older Than

Date

No

(Empty)

ISOLDERTHAN=

"%DateSerial(2001,10,12) + TimeSerial(00,00,00)%"

Causes this action to only include files if the source is older than the date/time specified. If this parameter is left blank or not included, the date of the files will be ignored.

↑ Top of Page

Attributes Properties

Property

Type

Required

Default

Markup

Description

Attributes

Text (Options)

No

(Empty)

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

This group of settings causes the action to filter which files should information be retrieved from 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 copy.

Available Options:

  • 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 Properties

The Description tab allows you to customize the text description of any step as it appears in the Task Builder's Steps Pane.

More on setting custom step description

Error Causes Properties

The Error Causes tab allows you to select/omit specific errors that should cause a particular step to fail.

More on Error Causes properties

On Error Properties

The On Error tab allows you to determine what the task should do if a particular step encounters an error.

More about On Error properties

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

Type

Return Value

theDataset.Source

Text

The path and file name of the source file.

theDataset.Destination

Text

The path and file name of the destination file.

theDataset.Result

Number

The result of this operation - 0 for success, or the corresponding error code (number) for failure.

theDataset.Message

Text

The textual information associated to the result.

Variables and Expressions

All text fields allow the use of expressions, which can be entered by surrounding the expression in percentage signs (example: %MYVARIABLE%, %Left('Text',2)%). To help construct these expressions, you can open Expression Builder from these fields by pressing F2.

More on variables
More on expressions

More on the expression builder

Example

NOTE: The code below can be copied and pasted directly into the Steps pane of the Task Builder.

 

Example 1 - Simple copy file operation.

 

<AMFILECOPY SOURCE="C:\Folder1\*.*" DEST="C:\Folder2" SUBFOLDERS="YES" KEEPFOLDERSTRUCT="NO" OVERWRITE="YES"  RESULTDATASET="FileCopyDataset" />

 

 

Example 2 - Copy file(s) from "C:\Folder1\*.*" to "C:\Folder2\". Include sub folders. Exclude the file mask(s) "*.pri". Overwrite read-only files and files that exist exist in the destination. Create and populate dataset "FileCopyDataset" with details of the file(s) to be copied.

 

<AMFILECOPY SOURCE="C:\Folder1\*.*" DEST="C:\Folder2" SUBFOLDERS="YES" OVERWRITE="YES" ISNEWER="YES" OVERWRITEREADONLY="YES" ONLYIFEXIST="YES" ISNEWERTHAN="%DateSerial(2007,02,24) + TimeSerial(15,40,34)%" ARCHIVETURNOFF="YES" EXCLUDE="*.pri" ATTRFILTER="+a-s" RESULTDATASET="FileCopyDataset" />

 

↑ Top of Page