Insert in File |
Inserts text into a file, at the specified position.
Syntax
Insert in File [ Select ; Result (error) ; Source filePath ;
Destination filePath ; Text to insert ; Position ;
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 |
Source filePath | the path to the source file |
Destination filePath | (optional) the path to the destination file |
Text to insert | the text to insert into the file |
Position | (optional) position where to insert the text. This is calculated in number of bytes from the beginning |
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 |
$$-43 | fnfErr | Source file not found |
Other errors may be returned.
Originated in
Troi File Plug-in 9.0
Compatibility
FileMaker Pro 17 to FileMaker Pro 21 (2024)
Considerations
If the position parameter is 0 or is empty, the text will be inserted at the beginning of the file.
For most situations it is best to insert with encoding UTF-8.
If Destination filePath is left is empty, the insertion text will be saved in the source file itself. This happens also when you specify the same source file and destination file.
Example
Insert in File [ Select ; $ErrorCode ; "HD Mac:data:My Letter" ;
"HD Mac:data:My newLetter" ; "my extra text" ; "42" ]
This will insert the text “my extra text” after the 42nd byte and save the result into the new file “HD Mac:data:My newLetter”.
Related script steps
Append to File |
Set Contents of File |
Show Select File Dialog |
Related function
TrFile_InsertContents |
Related topics
Troi File Plug-in online help (overview)