Version: 5
restore

Contents

Method

AppendText

ModuleFileContent
LibraryFileContent
Action

Append the supplied text to the specified file. If the file does not exist it is created using any specified encoding, and then the file is closed. If the file already exists and has content then an encoding should not be specified.

Parameters

FilePath (string; required): The full path of the file. The file will be created if it doesn't exist. Supports environment variables.

Text (string; required): The text string to be appended to an existing file or written to a new file.

Backup (bool; optional): Whether or not to backup the file prior to writing. If the file already exists, a copy of the file will be made in the same directory with the .bak suffix. If this backup file already exists, an incrementing number will be added after the extension. If a backup cannot be created, this method will return an error. Default is false.

NewLine (bool; optional) If true an O/S-specific line separator sequence will be written before the Text is written or appended.

Encoding (string, optional): File content encoding. Valid values are:

  • “ANSI”
  • “UTF8” – UTF8 with a byte order mark.
  • “UTF8NOBOM” – UTF8 without a byte order mark.
  • “UTF16LE” – UTF16 little endian byte order.
  • “UTF16BE” -UTF16 big endian byte order.

The default is "UTF8NOBOM".

If the file already exists and has content then an encoding should not be specified.

Return values

ExpandedFilePath (string): The file path of the written file, with any environment variables expanded.

Success (bool): Indicates whether the method succeeded.

BackupFileName (string): The full path of the backup file created if Backup is true. A NULL is returned if Backup is false.

Example

Append a sequence of text with line separators to file orwell.txt.

@lines = SELECT 'The clock' AS line UNION SELECT ' struck ' AS line UNION SELECT "thirteen o'clock" AS line;

FOREACH @line IN @lines DO
    FileContent.AppendText(FilePath : "orwell.txt", Text : @line, NewLine : true);
DONE;
Platforms
  • Windows
  • Linux
  • MacOS
  • Solaris Intel
  • Solaris SPARC
Notes