§23.14. Writing, reading and appending text to files
Text can also be saved to a file, and again all file-handling is automatic:
write (text) to (external file)
This phrase makes the given text become the entire contents of the named file. Note that files must have been declared, and must be referred to by their Inform names, not by textual filenames. Example:
write "Jackdaws love my big sphinx of quartz." to the file of Abecedary Wisdom;
append (text) to (external file)
This phrase adds the given text to the end of the current contents of the named file (creating it if it does not exist on disc). Note that files must have been declared, and must be referred to by their Inform names, not by textual filenames. Example:
append "Jinxed wizards pluck ivy from the big quilt." to the file of Abecedary Wisdom;
The quoted text can, of course, contain substitutions, so can be long and complex if need be.
Text from a file is printed back with the text substitution:
say "[text of (external file)]"
This text expands to the contents of the named file. Note that files must have been declared, and must be referred to by their Inform names, not by textual filenames. Example:
"[text of the File of Abecedary Wisdom]"
To copy one file to another, for instance,
write "[text of the file of Abecedary Wisdom]" to the file of Secondary Wisdom;
![]() | Start of Chapter 23: Figures, Sounds and Files |
![]() | Back to §23.13. Writing and reading tables to external files |
![]() | Onward to §23.15. Exchanging files with other programs |
|
|