Append to File
Append to File
Section titled “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).
How it works
Section titled “How it works”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.
Required parameters
Section titled “Required parameters”| Parameter | Type | Default | Description |
|---|---|---|---|
path | string | — | File path, including its folder (absolute or with asset(...)). |
content | string | — | Text to append. If the expression is null, no text is appended (the line break still is, when it applies). |
Optional parameters
Section titled “Optional parameters”| Parameter | Type | Default | Description |
|---|---|---|---|
encoding | string | "utf-8" | File encoding: utf-8, iso-8859-1, utf-16, utf-32, us-ascii… See encoding. |
newLine | bool | true | Puts a line break before the content when the file already exists. |
Output
Section titled “Output”Returns a string with the file path (as you gave it in path), in case you want to use it in a later activity.
Common errors
Section titled “Common errors”| Message | Cause 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.
Example
Section titled “Example”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: summaryLog message = "Processed: " + summaryRelated activities
Section titled “Related activities”- Write File — create or replace the whole file.
- Read File — read the accumulated content.