PALATINELABSDocsENES

Pages

↑↓ to moveEnter to openEsc to close

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.

Jump to actions

Packages

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.

IDFieldType; default; requirementUse
filePathSource fileStringdefault ""requiredAn existing text file you can read, for example samples/invoice.txt⁠. A relative path starts at the Run working folder. An empty path or a missing file fails.
encodingText encodingTextEncodingdefault FILE_ENCODINGoptionalHow the file is read; see the choices below.
trimLeadingSpaceTrim leading spacesBooleandefault falseoptionaltrue removes spaces and tabs at the start of each line. It does not remove spaces after = in a key=value line.
trimTrailingSpaceTrim trailing spacesBooleandefault falseoptionaltrue 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 choiceReads as
FILE_ENCODINGThe BOM if the file has one, otherwise UTF-8.
ANSIWindows-1252.
UTF8_WITHOUT_BOM⁠, UTF8UTF-8.
UTF16BEUTF-16 big-endian.
UTF16LE⁠, UNICODEUTF-16 little-endian.
Shift_JISShift-JIS.
WIN1251Windows-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

IDTypeResult / editor field
resultStringComplete 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.

Back to actions

Read variables (textFileReadVariables)

Read key=value lines into one Dictionary of String values.

Inputs

Also uses the shared fields.

IDFieldType; default; requirementUse
convertDictKeyToLowercaseConvert dictionary keys to lower case before assignment to variablesBooleandefault falseoptionaltrue⁠: make keys lowercase. Keys that then match replace earlier values. Values do not change.

Outputs

IDTypeResult / editor field
resultDictionaryParsed 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 {}.

Back to actions