Statement: file
The file statement is used to both define a file code and to open a text file for later use with the write statement or @read function.
file Statement | ||
---|---|---|
Format | Example | Note |
file filecode; | file note; | Define a file code. |
file filecode mode filename; | file note append "note.txt"; | Define a file code and prepare a file for use. |
file.filecode mode filename; | file input read "input.txt"; | Prepare an already defined file code file for use. |
The filename is expected in the form of a string expression.
The mode can be one of the following names:
Mode | Note |
---|---|
read | Open an existing file for reading text. |
write | Open for writing, truncating any existing text. |
append | Open for writing, adding new text to the end. |
The file code can only be defined once. To open or reopen a file, the file code must be used as a qualifier, by adding a '.' (period) between the 'file' and 'filecode'.
Example Script |
---|
let filename = "Notes-file.txt"; file note write filename; write.note "This is a test string." nl; write.note "And this is a second." nl; file.note read filename; write @read.note nl; write @read.note; |
Output:-This is a test string.
And this is a second.
|