Inform 7 Home Page / Documentation


§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. E ample:

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;


arrow-up.png Start of Chapter 23: Figures, Sounds and Files
arrow-left.png Back to §23.13. Writing and reading tables to external files
arrow-right.png Onward to §23.15. Exchanging files with other programs

*ExampleThe Fourth Body
Notebooks in which the player can record assorted notes throughout play.

**ExampleThe Fifth Body
An expansion on the notebook, allowing the player somewhat more room in which to type his recorded remark.