## Write Text File

The Write Text File function is used 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 function 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 variables referenced 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.

This statement is often used along with the Run External Script statement to write an on-the-fly script file. As a convenience, if the content to be written is empty (zero characters) and the filename extension evaluates to be yatesh, the file will be deleted.