FileMaker Pro 18 adds a number of new file script steps. In previous versions of FileMaker these external file manipulations were only possible with the help of Troi File Plug-in. Here you’ll find how the native file functionality of FileMaker 18 compares to the features of Troi File Plug-in.
Create a data file and set its contents
FileMaker 18 adds the new script steps ‘Create Data File’, ‘Open Data File’, ‘Write to Data File’ and ‘Close Data File’. You can use these to create a new (text) file, which you can then open and write data from your database into. After that you need to close the file again.
With Troi File Plug-in you can perform the same action using its ‘Create File‘ and ‘Set Contents of File‘ script steps (or their equivalent functions in FileMaker 15 and earlier). You don’t have to open and close the file, as that is automatically handled by the ‘Set Contents of File’ script step.
FileMaker’s ‘Write Data to File’ step lets you choose the character encoding to be UTF-16 (little endian) or UTF-8. With Troi File Plug-in’s ‘Set Contents of File’ step you can choose the following character encodings:
-Encoding=Native (default)
-Encoding=UTF8
-Encoding=ASCII_DOS
-Encoding=ASCII_Windows
-Encoding=ASCII_Mac
-Encoding=ISO_8859_1 (Windows Latin-1)
-Encoding=BytesOnly (only characters in the range 0-255 are written, others are skipped)
Troi File Plug-in’s ‘Set Contents of File’ step also allows you to automatically change all line endings in the written text (which are carriage returns in FileMaker) to Windows line endings (carriage return followed by a linefeed). FileMaker 18’s ‘Write Data to File’ step only allows for appending a line feed at the end of the written text.
Write data to an existing file
FileMaker 18 adds a new ‘Set Data File Position’ script step which lets you set the position (in number of bytes from the beginning of the file) at which to start reading or writing data. When you next write data to the file with the ‘Write to Data File’ step, existing text at the read-write position in the file is overwritten by the new data. If you want to append text to the end of an existing file, the steps would be:
Get File Size (to find the number of bytes for setting the read/write position at the end of the file)
Open Data File
Set Data File Position (to the number found by the Get File Size step)
Write to Data File
Close Data File
To add characters to the end of an existing file with Troi File Plug-in simply use the Append to File step. The plug-in offers two other script steps you can use to add data to or replace data in existing files. To insert text into an existing file at a specified position (without overwriting any existing data in the file) use the Insert in File script step. And to overwrite some text in an existing file, use the Substitute In File script step. This does not work by specifying a position, but by specifying a set of characters. The ‘Substitute In File’ script step will then replace every occurrence of this set of characters in the file with another set of characters you specify. And you can either overwrite the existing file or save the result into a new file you specify the name and path for.
Of course all these steps also allow you to specify the character encoding to be used.
Get the contents from an external file
FileMaker 18 adds the new script step ‘Read from Data File’ to read the contents of an external file into the database. As with the ‘Write Data to File’ step, you have to first Open the file and after reading Close the file. To read only part of an external file you can use the ‘Set Data File Position’ to indicate at which position to start reading and you can specify the number of bytes or (for UTF-16) the amount of Unicode code units to read.
With Troi File Plug-in you can use the TrFile_GetContents function to get the contents of a file. It also allows you to specify the starting position and the number of characters to get. Moreover, you can specify the character encoding of the text to be read and you can convert any line breaks in the data to the line break FileMaker expects: this means that CRLF, LF and CR will all become CR (carriage return).
If you want the user to determine which file to read the contents from, you can alternatively use the plug-in’s Get File Contents with Dialog script step. This will show the user a file selection dialog and return the contents of the selected file, all with one easy script step!
Other file script steps
Here is a list of other file script steps introduced in FileMaker 18, with their equivalent steps or functions in Troi File Plug-in:
FMP 18 | Troi File Plug-in |
Delete File | Delete File |
Get File Exists | TrFile_Exists |
Get File Size | TrFile_GetFileSize |
Rename File | Move File |
This list does not show all features of Troi File Plug-in. It only lists the ones related to the new features of FileMaker Pro 18. Apart from deleting and renaming files, for example, Troi File Plug-in can also delete folders and rename (or move) folders, copy files and folders, create folders, reveal files and folders in the macOS Finder or Windows Explorer, zip and unzip files and folders and much more!
Troi File Plug-in adds no less than 80 functions and 38 scripts steps to work with files and folders outside the FileMaker database. For an overview of all functions and steps added by the plug-in please see the online help page. Or download the fully functional demo version from the File Plug-in web page and see what you can do with it right away.