Set Contents of File (script step reference)

By January 1, 2021January 26th, 2021Online Help, Troi File Plug-in
Troi File Plug-in > Script steps reference > Set Contents of File
Troi File Plug-in for FileMaker Pro

Set Contents of File

Sets the contents of a file.

SyntaxScript step badge

Set Contents of File [ Select; Result (error) ; FilePath ; Text to set ;
                       Encoding ; Line endings ]

Options

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
Result (error) an error code
FilePath the path to the file
Text to set the characters that you want to write as the contents of the file
Encoding the desired character encoding like UTF-8
Line endings 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

Returned Result

Data type returned

Error code

Result

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:

0 no error The string of characters was written in the file
$$-1 genericErr The file could not be opened for writing (You may need to create the file first).

Other errors may be returned.

Originated in

Troi File Plug-in 9.0

Compatibility

FileMaker Pro 16 to 19

Considerations

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.

Example

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 stepScript step badge

Insert in File

Related functionFunction badge

TrFile_SetContentsOfFile

Related topics

Troi File Plug-in online help (overview)


Online Help Page for Troi File Plug-in for 16 to 19 –> Set Contents of File (filep7273) 2021-0125 20:48:13