Loop File Contents

Declaration

<AMLOOP TYPE="FILECONTENTS" FILE="text" RESULTVARIABLE="text" DELIMITER="text(options)">

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 contents of the specified text file and populates a variable with the current string of delimited text. The loop ends at the end of the file or if a Break step is encountered. This action wraps the functionality of a Read from File action and a Loop List action into one concise loop structure.

Practical Usage

Used to perform one or more actions on each item in a delimited text file.

Parameters

General Properties

Property

Type

Required

Default

Markup

Description

File

Text

Yes

While

FILE="C:\Temp\FileName.txt"

The file that contains the text to loop through.

Populate Variable with file data

Text

Yes

(Empty)

RESULTVARIABLE="varname"

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

Delimiter

Text (options)

No

New Line

DELIMITER="comma"

The character that delimits the text in the file. The available options are:

  • Comma: The delimiter is a comma (Example: item1,item2,item3).

  • New line: The delimiter is a new line (default).

  • Semi colon: The delimiter is a semi colon (Example: item1;item2;item3).

  • Space: The delimiter is a space (Example: item1 item2 item3).

  • Tabulation: The delimiter is a tab character.

  • Custom: The delimiter is another character as specified (simply enter the character in the provided text-box).

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 properties lets you instruct a task step to react only to specific errors or ignore certain errors that should cause it to fail.

More on Error Causes properties

On Error Properties

The On Error tab properties lets you determine what the task should do if a particular step encounters an error as defined in the Error Causes properties.

More about On Error properties

Additional Notes

Expressions, Variables & Functions

A percent sign is used as a special character in AutoMate to indicate the beginning and end of an expression. This allows variables, functions and other expressions to be entered in any text parameter of a task's properties. For example: %1+1% inside a task will resolve to 2 at runtime. A more elaborate example is %FileDateTime(myFile)% which results to the date/time of myFile. To help construct expressions, you can open Expression Builder by clicking the Insert Expression (%) button or by pressing F2.

More on expressions

More on variables

More on functions

More on extended functions
More on the expression builder

Example

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

 

Description: This task uses a Write to File action to write the text "This is the space delimited text." to C:\Temp\theSampleFile.txt. A Loop File Contents action then reads the space delimited contents of that file and displays each in a message box.

 

<AMVARIABLE NAME="mycounter">1</AMVARIABLE>

<AMLOOP TYPE="EXPRESSION" EXPRESSION="mycounter=5" CONDITION="until">

     <AMSHOWDIALOG MESSAGE="%mycounter%" />

     <AMINCREMENTVARIABLE RESULTVARIABLE="mycounter" />

</AMLOOP>

 

↑ Top of Page