Set Contents of File
Sets the contents of a file.
Set Contents of File [ Select; Result (error) ; FilePath ; Text to set ;
Encoding ; Line endings ]
|Select entire contents
|replaces the entire contents of a field with the result. If not checked the result replaces the currently selected portion of the field
|an error code
|the path to the file
|Text to set
|the characters that you want to write as the contents of the file
|the desired character encoding like UTF-8
|choose "Don’t change" or "CR to CRLF (Windows)" to change return characters in the text to CRLF (Carriage Return followed by a Line Feed) in the inserted text
Data type returned
The returned result is an error code. An error always starts with 2 dollars, followed by the error code. You should always check for errors. Returned error codes can be:
|The string of characters was written in the file
|The file could not be opened for writing (You may need to create the file first).
Other errors may be returned.
Troi File Plug-in 9.0
FileMaker Pro 16 to FileMaker Pro 2023
See also the functions:
Show Save File Dialog to get a FilePath for the file.
Note that the maximum size of Set Contents Of File is currently 150 million characters which equals to about max. 600 million characters written. This depends on the encoding, for example one Unicode character encoded as UTF-8 can require up to 4 characters in the written file.
Use the Append Contents to File script step if you need to append more characters.
To be able to export all possible characters (like Chinese characters) it is best to export with encoding UTF-8.
Assume your C disk already contains a file “Testtext.txt” which is empty. We assume that a global number field gErrorCode is defined. Create the following script:
Set Contents of File [ Select ; gErrorCode ; "C:\Testtext.txt" ; "Hello there." ]
This script will set the contents of the file “C:\Testtext.txt” to the text “Hello there.”.
Related script step
|Insert in File