Application icon

Write Text File

The Write Text File statement is used to write a file with the contents of a named variable. The file is written using the specified encoding. Note that on a Mac the preferred encoding is UTF8.

If you select the Lossless writes only option, the write will fail if data will be lost when writing to the specified encoding. If you do not select the option, the write will typically succeed, but encodings other that of UTF8 or UTF16 variants may lose characters during the write.

You can choose to append the data to a file if the file already exists.

Both of the supplied strings may contain any of the escape sequences described in Escape Sequences. The resultant file path may be absolute (/), relative to the Home folder (~/) or relative to the track's containing folder (./) or (../).

While this statement is valid in all execution modes, it will typically be performed in stepwise mode so that the file is written only once. When run stepwise any escape sequences in the supplied strings are taken from the first selected file and a relative path is relative to that same file.

If the specified path does not exist, it will be created, even if the append option has been specified.

If the file is successfully written the action test state will be set to true. If the file is not successfully written, the action test state will be set to false.

If you want to test if an encoding will lose data, select the Test only option. When this option is selected, no attempt will be made to write a file. The action test state will be set to true if no data loss will occur, otherwise false.

If the Delete the file if the content is empty option is set the file will be deleted when the content is empty (zero characters). Careful here. The file is deleted ...not moved to the trash! If the file is deleted or did not exist, the action test state will be set to true, otherwise it will be set to false.

This statement is often used along with the Run External Script statement to write an on-the-fly script file. For historic reasons, if the content to be written is empty (zero characters) and the filename extension evaluates to be yatesh, the file will be deleted, even if the Delete the file if the content is empty option is not set.


Writing Binary Files

While not designed specifically to do so, Yate can write binary files. See the Working With Binary Files topic.