Write File
Write File
Section titled “Write File”Type: write-file · Package: Filesystem Activities v1.0.6 · Output: string
Writes a text string to a file. If the file does not exist, it creates it; if it exists, it replaces it by default. Use it to produce output files: a log, a text report, a settings file.
How it works
Section titled “How it works”Writes content to the file at path.
- Overwriting: by default it replaces the existing file (
overwrite = true). If you setoverwrite = falseand the file already exists, the activity fails instead of replacing it, leaving it untouched. - Folders: if the file’s folder does not exist, it is created (with any intermediate ones).
- Encoding: with
utf-8(default) the file starts with the UTF-8 BOM, which Excel and Notepad recognize. See encoding. - Exact content: writes the text as is, without adding a line break at the end. If
contentis null, it creates an empty file. - Idempotent with
overwrite = true: repeating it gives the same result.
Required parameters
Section titled “Required parameters”| Parameter | Type | Default | Description |
|---|---|---|---|
path | string | — | Path of the file to write, including its folder. |
content | string | — | Text to write. Other types are converted to text. |
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. |
overwrite | bool | true | Replace the file if it already exists. With false, the activity fails if it exists. |
Output
Section titled “Output”Returns a string with the path of the written file (as you gave it in path).
Common errors
Section titled “Common errors”| Message | Cause and fix |
|---|---|
The file already exists and 'overwrite' is false. | You set overwrite = false and the file exists. Use a unique name, delete it first, or keep overwrite = true. |
The process cannot access the file '…' because it is being used by another process. | The file is open in another program. |
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”Produce a summary and attach it to an email:
Write File path = pathJoin(outputFolder, "summary.txt") content = "Process completed: " + now().ToString("yyyy-MM-dd HH:mm") → output: summaryPathSMTP Send ... subject = "Process summary" attachments = arr(summaryPath)Related activities
Section titled “Related activities”- Append to File — add to the end without replacing.
- Read File — read the file back.