ForEach...File...Do...Od

You can use the ForEach … File statement to process lines from a file.

Syntax

ForEach Line
encoding File "path\filename"
Do
... ;
Od;

ForEach Line is a variable declared as Text. Common practice is to use Line as variable name because it contains the current line at each passing.

File "path\filename" is the file path and name. Each line of this file is used to execute the part Do ... Od

... ; is repeated code.

Optionally, the script can specify an encoding. Supported encoding keywords are:

  • UTF8

    The data is interpreted as variable-length UTF-8 encoding.

    Invalid byte sequences are mapped to the U+FFFD REPLACEMENT CHARACTER (_invalidchar).

  • UTF16

    The data is interpreted as double-byte little-endian (Windows) UTF-16 characters.

  • Auto

    If the file begins with an UTF-8 or UTF-16 BOM (byte order mark), the file is read in the appropriate encoding. If no BOM is found, the file is interpreted as single-byte characters in the system ANSI codepage.

If no encoding is specified, the file is interpreted as single-byte characters in the system ANSI codepage.

Every line is assigned to the variable before Do … Od is executed. You can use the Break command to terminate the loop unconditionally.

Example

Var Text Line;

ForEach Line UTF8
File "c:\temp\log"
Do
  Progress Message (Line);
Od;

This reads the file C:\temp\log, interprets the data as UTF-8, and sends every line back to the client as a separate message.