Loop Files

Declaration

<AMLOOP TYPE="FOLDER" FOLDER="text" ONLYFILENAME="Yes/No" SUBFOLDERS="Yes/No" EXCLUDE="text" SORT="test(options)" ISNEWERTHAN="date" ATTRFILTER="text" RESULTDATASET="text">

See Also

Loop | End Loop | Loop Files | Loop Windows | Loop Processes | Loop Expression | Loop Dataset | Loop List | Loop List Control | Loop Processes | Loop Tree Control | Loop Windows | Break

Description

Loops through the file names contained in the folder specified. The variable specified is updated with the current file name. With each successive loop, the next file name is retrieved. The loop ends after all the file names have been retrieved or when a Break is encountered. This action accepts wildcards (* and ?).

Practical Usage

Ideally used to perform an action on every file in a folder or perform actions on files in batches, such as re-sizing all image files in a folder.

Parameters

General Properties

Property

Type

Required

Default

Markup

Description

Folder

Text

Yes

While

C:\FolderName\SubfolderName"

The folder that should be scanned for files. This parameter also acts as an Include Filter and accepts wildcard characters such as * and ?. To specify more than one file, use the pipe "|" character.

Populate variable with file data

Text

Yes

(Empty)

RESULTVARIABLE="varname"

The name of the variable that should be populated with the next file name on each successive loop.

Create and populate dataset with result info

Text

No

(Empty)

RESULTDATASET="DatasetName"

The name of a dataset to be created and populated with specific information regarding the files being looped through. More on the dataset that this action creates can be found below under Notes.

Do not include path info

Yes/No

No

No

ONLYFILENAME="yes"

If set to YES (enabled), only the file name and not the path information (drive and folder name) will be returned in the variable or dataset. If set to NO (default), the full path and file name will be returned.

 

Advanced Properties

Property

Type

Required

Default

Markup

Description

Exclude Mask

Text

No

(Empty)

EXCLUDE="*.txt"

Indicates a wildcard mask to designate files that should be omitted from the loop. Asterisk (*) or question mark (?) can be used as wildcard characters. For example, if *notepad* was specified, the loop would ignore file that included the text notepad in its name. To specify multiple wildcard masks, separate each one with a pipe (|) character (*.txt|*.jpg).

Include Subfolders

Yes/No

No

No

SUBFOLDERS="yes"

If set to YES (or enabled), specifies that the loop will include files or folders inside subfolders of the folder specified. By default, subfolders are not included.

Include Folders

Yes/No

No

No

FOLDERS="yes"

If set to YES (or enabled), specifies that the loop will include folders as an item to loop. By default folders are not looped.

Include Files

Yes/No

No

Yes

FILES="yes"

If set to YES, specifies that the loop will include files as an item to loop. By default, files are looped.

Sorting

Text (options)

 

No

Do not sort list

SORT="ascending"

Specifies whether a sort order should be applied towards the list of processes before the loop begins. The available options are:

  • Do not sort list (default)

  • Sort the list in ascending alphabetical order

  • Sort the list in descending alphabetical order

Field to sort on

Text (options)

No

File Name

SORTON="size"

The field to use in sorting the files. Valid only if the Sorting parameter is set to Ascending or Descending. The available options are:

  • File Name: The name of the file.

  • CDate Created: The date the file was created.

  • Date Modified: The date the file was last modified.

  • File Size: The size of the file.

 

Date Filter Properties

Property

Type

Required

Default

Markup

Description

Only if Newer Than

Date

No

(Empty)

ISNEWERTHAN=

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

If enabled, causes this action to only act on files that are newer than the date/time specified. If this parameter is left blank or disabled (default), file dates are ignored.

Click the Custom button to select from a list of pre-defined date parameters. Enable the Expression option to allow entry of a date/time expression.

Only if Older Than

Date

No

(Empty)

ISOLDERTHAN=

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

If enabled, causes this action to only act on files that are older than the date/time specified. If this parameter is left blank or disabled (default), file dates are ignored.

Click the Custom button to select from a list of pre-defined date parameters. Enable the Expression option to allow entry of a date/time expression.

 

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 this action to filter which files are affected by the attribute change based on the original attribute settings of the source files.

In visual mode, a group of controls are provided to assist in the selection of this parameter. In AML mode, a single text item must be specified that contains the original attribute mask of the files you wish to affect.

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.

 

Custom Description

This action includes the Description tab for entering a custom step description.

More on setting custom step description

Standard Error Handling Options

This action also includes the standard Error Causes and On Error failure handling options/tabs.

More on Error Handling Options

Notes

Datasets

This action creates a dataset with the following fields (assuming the name of the dataset is theDataset):

Name

Data Type

Return Value

theDataset.Name

Text

Returns the name of the file.

theDataset.Size

Number

Returns the file size.

theDataset.CreatedOn

Date

Returns the file creation date.

theDataset.ModifiedOn

Date

Returns the date the file was last modified.

theDataset.AccessedOn

Date

Returns the date the file was last accessed.

theDataset.IsFolder

Yes/No

Returns whether the file name is a folder (yes/no).  

theDataset.IsReadOnly

Yes/No

Returns whether the file attribute is read-only (yes/no).  

theDataset.IsArchive

Yes/No

Returns whether the file attribute is archive (yes/no).  

theDataset.IsSystem

Yes/No

Returns whether the file attribute is system (yes/no).

theDataset.IsHidden

Yes/No

Returns whether the file attribute is hidden (yes/no).  

theDataset.IsCompressed

Yes/No

Returns whether the file is compressed (yes/no).  

theDataset.IsAccessible

Yes/No

Returns whether the file is accessible (yes/no).

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.

 

Sample 1 - This task loops through all files that reside in c:\temp. Only file names are populated. A message box will display each file name within each successful loop. For this task to work, create a c:\temp folder and add some files to it or modify step 2 (Loop Files action) to point to a valid directory that includes some files.

 

<AMVARIABLE NAME="theCurrentFile"></AMVARIABLE>

<AMLOOP TYPE="FOLDER" FOLDER="C:\Temp" RESULTVARIABLE="theCurrentFile" ONLYFILENAME="YES">

     <AMMESSAGEBOX>The current file is %theCurrentFile%</AMMESSAGEBOX>

</AMLOOP>

 

 

Sample 2 - This task loops through all folders only (no files) that reside in c:\temp. Folders are sorted in ascending alphabetical order. A message box will display each folder name within each successful loop. For this task to work, create a c:\temp folder and add some subfolders to it or modify step 2 (Loop Files action) to point to a valid directory that includes some folders.

 

<AMVARIABLE NAME="theCurrentFolder"></AMVARIABLE>

<AMLOOP TYPE="FOLDER" FOLDER="C:\Temp" RESULTVARIABLE="theCurrentFolder" ONLYFILENAME="YES" FOLDERS="YES" FILES="NO" SORT="ascending" RESULTDATASET="theDataset">

     <AMMESSAGEBOX>The current folder is %theCurrentFolder%</AMMESSAGEBOX>

</AMLOOP>

 

↑ Top of Page