Skip to content

Append to File

Type: append-file  ·  Package: Filesystem Activities v1.0.6  ·  Output: string

Appends text to the end of a file without erasing what is already there. If the file does not exist, it creates it. It is the ideal activity for building logs or accumulating lines over one run (or several).

Appends content to the end of the file at path.

  • Line break: with newLine = true (default) and an existing file, it puts a Windows line break (\r\n) before the content, so each call lands on its own line. If the file did not exist, it writes the content with no leading break. It never adds a break at the end.
  • Folders: if the file’s folder does not exist, it is created (with any intermediate ones).
  • Encoding: with utf-8 (default), a new file starts with the UTF-8 BOM. Use the same encoding for every call on the same file. See encoding.
  • Not idempotent: each run appends the text again. If you retry it with Retry, the line may end up duplicated.
ParameterTypeDefaultDescription
pathstring—File path, including its folder (absolute or with asset(...)).
contentstring—Text to append. If the expression is null, no text is appended (the line break still is, when it applies).
ParameterTypeDefaultDescription
encodingstring"utf-8"File encoding: utf-8, iso-8859-1, utf-16, utf-32, us-ascii… See encoding.
newLinebooltruePuts a line break before the content when the file already exists.

Returns a string with the file path (as you gave it in path), in case you want to use it in a later activity.

MessageCause and fix
The process cannot access the file '…' because it is being used by another process.The file is open in another program. Close it or use a different file.
Access to the path '…' is denied.No write permission on the folder, or the file is read-only.
'windows-1252' is not a supported encoding name…The encoding is not available. Use iso-8859-1 or utf-8.
'path' is required.The path expression evaluated to null.

If path is just a file name, it is written to the robot’s working folder (since version 1.0.6; before, the activity failed). Use a full path so you always know where the file ends up.

Log each processed item to a file and show its content at the end:

For Each items = invoices itemVariable = invoice
└─ activities:
... process ...
Append to File path = "C:/logs/processed.txt" content = invoice.number + " — OK" → output: logPath
Read File path = logPath → output: summary
Log message = "Processed: " + summary