Loop - File contents |
Declaration
<AMLOOP ACTIVITY="filecontents" FILE="text" RESULTVARIABLE="text" ENCODING="text (options)" DELIMITER="text (options)" />
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.
Practical Usage
Used to perform one or more activities on each delimited item in a text file. This activity wraps the functionality of a Read from file and a Loop list activity into one concise loop structure.
Parameters
General
Property | Type | Required | Default | Markup | Description |
---|---|---|---|---|---|
File | Text | Yes | While | FILE="C:\Temp\FileName.txt" | The path and file name of the file that contains the data to loop through. |
Populate variable with file data | Text | Yes | (Empty) | RESULTVARIABLE="varname" | The name of an existing variable to populate with the next delimited string on each successive loop. |
Encoding | Text (options) | No | ANSI |
| The character encoding system to use. Proper encoding may be required in order to facilitate the transmission of data through telecommunication networks or for storage purposes on non-Windows operating systems. The available options are:
|
Delimiter | Text (options) | No | New line (\n) |
| The character used to separate each string of text to loop through. The available options are:
|
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 task uses a Write to File activity to write the text "This is the space delimited text." to C:\Temp\theSampleFile.txt. A Loop File Contents activity then reads the space delimited contents of that file and displays each in a message box.
<AMVARIABLE NAME="var_text" VALUE="" />
<AMLOOP ACTIVITY="filecontents" FILE="C:\Temp\theSampleFile.txt" RESULTVARIABLE="var_text" DELIMITER="space" />
<AMSHOWDIALOG>%var_text%</AMSHOWDIALOG>
<AMLOOP ACTIVITY="end" />