Loop - File contents

Declaration

<AMLOOP ACTIVITY="filecontents" FILE="text" RESULTVARIABLE="text" ENCODING="text (options)" DELIMITER="text (options)" />

Related Topics   

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

 
PropertyTypeRequiredDefaultMarkupDescription
FileTextYesWhileFILE="C:\Temp\FileName.txt"The path and file name of the file that contains the data to loop through.
Populate variable with file dataTextYes(Empty)RESULTVARIABLE="varname"The name of an existing variable to populate with the next delimited string on each successive loop.
EncodingText (options)NoANSI
  • ENCODING="ansi"
  • ENCODING="unicode"
  • ENCODING="unicodebigendian"
  • ENCODING="utf-8"

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:

  • ANSI - The standard for the core fonts supplied with US versions of Microsoft Windows.
  • Unicode - Industry standard for the consistent encoding, representation and handling of text expressed in most of the world's writing systems.
  • Unicode big endian - Architecture in which, within a given 16- or 32-bit word, bytes at lower addresses have lower significance (the word is stored ‘little-end-first’).
  • UTF-8 - Variable-width encoding that can represent every character in the Unicode character set. It was designed for backward compatibility with ASCII.
DelimiterText (options)NoNew line (\n)
  • DELIMITER="comma"
  • DELIMITER="new_line"
  • DELIMITER="semi-colon"
  • DELIMITER="space"
  • DELIMITER="tab"

The character used to separate each string of text to loop through. The available options are:

  • Comma - The delimiter is a comma (Example: item1,item2,item3).
  • New line (\n) - The delimiter is a new line.
  • Semicolon - The delimiter is a semi colon (Example: item1;item2;item3).
  • Space - The delimiter is a space (Example: item1 item2 item3).
  • Tab - The delimiter is a tab character.
  • Custom - The delimiter is a user-defined character. Enter the desired character in the provided text box.

Description

Error Causes

On Error

Example

NOTE:
  • Copy and paste the sample AML code below directly into the Task Builder Steps Panel.
  • To successfully run the sample code, update parameters containing user credentials, files, file paths, or other information specific to the task to match your environment.

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.

Copy
<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" />