Skip to main content

Text.write

writepath encoding on_existing_file on_problems

Group: Output

Documentation

Writes (or appends) the text to the specified file using the supplied encoding. The behavior specified in the existing_file parameter will be used if the file exists.

If a character cannot be converted to a byte, an Encoding_Error is raised. If on_problems is set to Report_Warning or Ignore, it is replaced with a substitute (either '�' (if Unicode) or '?' depending on the encoding). Otherwise, the process is aborted. If the path to the parent location cannot be found or the filename is invalid, a File_Error.Not_Found is raised. If another error occurs, such as access denied, an File_Error.IO_Error is raised. Otherwise, the file is created with the encoded text written to it. The method returns a File object for the written file.

Arguments

  • path: The path to the target file.
  • encoding: The encoding to use when writing the file.
  • on_existing_file: Specifies how to proceed if the file already exists.
  • on_problems: Specifies how to handle any encountered problems.

Remarks

Dry Run

If writing to Output context is not enabled (such as in "Design" mode), then this function will write to a temporary file. This temporary file will be automatically deleted on exit of the Enso process.

This allows for building the workflow without affecting the real files.