Text file package guide
Read complete text or key=value settings from a local file with explicit encoding and trimming controls.
Version 2.14.0. Installed versions can differ. Examples are illustrative and not tested.
Prerequisites
No session or other application is needed. The whole file is read into memory at once, with no size limit. Values read stay String, even when they look like numbers. Inputs left blank use the table defaults.
Shared fields
Both actions use these fields.
| ID | Field | Type; default; requirement | Use |
|---|---|---|---|
file | Source file | Stringdefault ""required | An existing text file you can read, for example samples/. A relative path starts at the Run working folder. An empty path or a missing file fails. |
encoding | Text encoding | Textdefault FILE_optional | How the file is read; see the choices below. |
trim | Trim leading spaces | Booleandefault falseoptional | true removes spaces and tabs at the start of each line. It does not remove spaces after = in a key=value line. |
trim | Trim trailing spaces | Booleandefault falseoptional | true removes spaces and tabs at the end of each line. |
Line breaks (LF or CRLF) stay. Files with only CR line breaks (old Mac) are read as one line.
| Encoding choice | Reads as |
|---|---|
FILE_ | The BOM if the file has one, otherwise UTF-8. |
ANSI | Windows-1252. |
UTF8_, UTF8 | UTF-8. |
UTF16 | UTF-16 big-endian. |
UTF16, UNICODE | UTF-16 little-endian. |
Shift_ | Shift-JIS. |
WIN1251 | Windows-1251. |
Actions
Get text (textFileRead)
Read the whole file as text. Line breaks stay; each line can be trimmed.
Inputs
Uses the shared fields.
Outputs
| ID | Type | Result / editor field |
|---|---|---|
result | String | Complete decoded and optionally trimmed text. Field: Save the outcome to a variable. |
Example
Create samples/invoice.txt containing alpha \nbeta\n, where \n means an LF line break. Set filePath=samples/invoice.txt, encoding=FILE_ENCODING, trimLeadingSpace=true, trimTrailingSpace=false. Bind result to $invoiceText$.
Expected result
$invoiceText$ is alpha \nbeta\n: leading spaces are removed on each line, trailing spaces and line breaks remain. An empty file gives an empty String.
Read variables (textFileReadVariables)
Read key=value lines into one Dictionary of String values.
Inputs
Also uses the shared fields.
| ID | Field | Type; default; requirement | Use |
|---|---|---|---|
convert | Convert dictionary keys to lower case before assignment to variables | Booleandefault falseoptional | true: make keys lowercase. Keys that then match replace earlier values. Values do not change. |
Outputs
| ID | Type | Result / editor field |
|---|---|---|
result | Dictionary | Parsed keys and String values. Field: Save the outcome to a variable. |
Example
Create samples/settings.txt with lines # sample, Host=api.example.com, Port = 443, and Mode=test. Set filePath=samples/settings.txt, encoding=FILE_ENCODING, convertDictKeyToLowercase=true, trimLeadingSpace=false, trimTrailingSpace=false. Bind result to $settings$.
Expected result
$settings$ is {"host":"api.example.com","port":" 443","mode":"test"}. Keys are trimmed; values after the first = are kept, including spaces and further = characters. Empty keys, blank lines, lines without =, and comment lines that start with # or ; (after spaces) are ignored. A repeated key keeps its last value. A file with no valid lines gives {}.