22.13. Writing, reading and appending text to files

| Chapter 22: Figures, Sounds and Files |

| 22.13. 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;

432
| Example The Fourth Body Notebooks in which the player can record assorted notes throughout play. |
RB

433
| Example The Fifth Body An expansion on the notebook, allowing the player somewhat more room in which to type his recorded remark. |
RB

Previous | Contents | Next