Skip to main content

FAQ Part 5: File Plug-in questions

By December 1, 2017January 26th, 2023FAQ

Creating files

Is it possible to write a TAB character (or any other special character) in a file in order to generate a log file that can easily be opened in another application, like Excel?

Yes, you can write any ASCII character to a file with Troi File Plug-in. You need to concatenate your ‘regular’ text with the special characters. The easiest way is to use the TrFile_AsciiValueToText function available in Troi File Plug-in 4.0 and later.
First define a global to hold the TAB:

gTABchar    global, text

Then fill this global with the help of a (startup) script, like this:

Set Field [ gTABchar ;
    TrFile_AsciiValueToText ( "-Unused" ; "9" ) ]

or with variables:

Set Variable [ $$TABchar ;
    TrFile_AsciiValueToText ( "-Unused" ; "9" ) ]

See also the example file MakeASCIIs.fmp12 in the File Plug-in download.
For this you need to know the character’s ASCII code, TAB has ASCII code 9. See the example file ASCII.fmp12 in the download of Troi Serial Plug-in for a list of ASCII codes. You can download Troi Serial Plug-in here.

How can I create a text file that has the correct formatting for the end of line for all platforms?

First create a global text field, for example called gXplatformReturn, which you set in a script that is run at startup of the file. In this script have the following step:

Set Field [ gXplatformReturn ; TrFile_AsciiValueToText ( "-Unused" ;
    If ( Abs ( Get (CurrentPlatform ) ) = 1 ;
    "13" ;
    "13 10" ) ;
    ) ]

On Mac OS this will result in a CR (Carriage Return) and on Windows this will result in a CRLF (Carriage Return followed by a LF (LineFeed) character).
Now you can simply append this global to your calculations, for example in this script step:

Set Field [ gErrorCode ; TrFile_AppendContents ( "-Unused" ; "A bit of text" &
    gXplatformReturn ) ]

TIP You can also define this as a global variable in FileMaker 8 or later.


I do not want a dialog for the user to determine which file to manipulate - I already know where the file is. How do I stop the dialog appearing?

In the example scripts these steps are performed: first a step that asks the user for a file and stores the resulting file path in a global. Then secondly this global is used in the next function to perform the actual action with that file. If you don’t want a user dialog you can omit the first step and give the known path to the file as a parameter to the second function. So omit this step that brings the dialog up from the script:

Set Field [ gTheFileSpec ;
    TrFile_SelectFileDialog ( "-Unused" ; "Please select a file:" ) ]

And only perform this step:

Set Field [ textField ;
    TrFile_GetContents ( "-Unused" ; gTheFileSpec ; ) ]

The global field ‘gTheFileSpec’ must contain a valid path to a file. You can also use a text field or calculation to specify the file.

How do I automatically append the CurrentDate to export files without going through a dialog?

Use the Troi File Plug-in for this: if you know the path to the export file you can do it. First do an automatic scripted export to a file, for example named ‘Export.TAB’. Then use:

Set Field [ gErrorCode ; TrFile_Movefile ("-Unused" ;
    gFilepath ; gFilepath & GetAsText ( Get ( CurrentDate ) ) ]

Here gFilepath is a global field and contains for example:
After using the function the name of the file will be 'ExportFile.TAB09291998'. The path will be:

The Troi File plug-in will only show text files in the selection dialog. How can you change this?

This is on Mac and is file filtering in action. To change the default filtering take a look at “Filtering Files” in the example databases.
For example to display all files add this script step:

Set Field [ dontcare ;
    TrFile_SetDefaultType ( "-Unused" ; "" ) ]

How can you display only text files in a SelectFileDialog box?

The fileTypes parameter must be formated in pairs of lines. You can specify multiple pairs of lines. The first line of the pair should contain a description of the files to be shown in the dialog. For example: “Text Files (*.txt)”.
The second line of the pair should contain the extension to be shown. For example: “*.txt”. Also in the second line you can use multiple extensions to filter on by separating them with a semi-colon “;”. For example: “*.txt;*.doc”.

Set Field [ dontcare ;
    TrFile_SetDefaultType ("-Unused" ;
    "Text Files (*.txt)¶"*.txt" ) ]

File formats

Can the File Plug-in read, write or modify Microsoft Word documents?

The File Plug-in can read or create any type of document. However, the File Plug-in does not know about the proper format for a Word document. So you can read in the contents of a document, but this will look like gibberish. The format of Microsoft Word is as far as we know not public, so we can’t help you decode the proper format.
If you want to create documents that Word can understand, you might try to calculate a RTF (Rich Text Format) formatted file.
Below you find an example of a Word document with only the text “Hello World”. This file can contain lots of extra information. A *part* of this file might be similar to this:

&endash;œ$%%^^¢£§§§§••••••¢ ¢ ˆ ˆ ˆ ˆ ¢ ˆ¢ d Hello World! ∞
∆A!∞ “∞ #êÝ
$êÝ %∞ ∞≈ ∞≈ ê≈

Not an easy read!

What is the difference in line end format between Mac and Windows?

In Mac text files the end of a line is signaled by the CR or Carriage Return character (ASCII code 13). In Windows files in general and specifically text files (extension .txt) the end of a line is signaled by CR/LF which is the Carriage Return character (ASCII 13) directly followed by the Line Feed character (ASCII 10).

I am looking for a tool to export from Windows FileMaker to Paradox, Excel, textfile or any other readable format. Do you know of any tools that may help?

The Troi File plug-in can create files exactly as you want them, provided you know how to create the format with a FileMaker calculation. The plug-in also has a substitute function, so you can even change (exported) files on disk to some other formats.

Images and Containers

Can the File plugin read metadata from raw images, like CR2 or NEF?

Troi File Plug-in will read IPTC and Exif metadata from JPEG, Raw and PNG images. The TrFile_GetMetaData function, with the switch “-GetEXIF” works with all RAW formats that are internally based on the TIFF format. Many (but not all) RAW file formats are based on TIFF, a.o. 3FR (Hasselblad), DCR, K25, KDC (Kodak), CR2 (Canon), ERF (Epson), MEF (Mamiya), MOS (Leaf), NEF (Nikon), ORF (Olympus), PEF (Pentax), RW2 (Panasonic) and ARW, SRF, SR2 (Sony).

Is there a Troi plug-in that can save an image which is stored inside a container field to a file?

Yes, in version 11 and later of Troi File Plug-in you will find the TrFile_ExportToFile function, which can save container data to disk. This function can also be used on FileMaker Server.

Graphics imported into a container and stored as a reference only are not visible on other computers. What gives?

When graphics are stored in container fields, referenced graphics will not be visible to guests unless they have mounted the volume where the graphics are stored before opening the database.

How come IPTC data contains garbage for higher ASCII's?

Higher ASCII characters are not defined in IPTC data, so the encoding can be Mac or Windows. Troi File Plug-in assumes the encoding is the same as the platform the plug-in is running on. If you run into this problem please use one of the following switches with the TrFile_GetMetaData function:
-SourceMacCharSet (if the IPTC data has Mac encoded characters)
-SourceWinCharSet (if the IPTC data has Windows encoded characters).
From version 6.0 the plug-in can automatically detect if the IPTC text is UTF-8 encoded and will return the metadata text correctly formatted. If UTF-8 format is detected it will override the switches “-SourceMacCharSet” and “-SourceWinCharSet”.

Information on files

I want to get the creation date en file size from all files in a folder. How can I do that with the File plug-in?

You’d have to do this in two steps. First use the TrFile_ListFolder function to get the list of all files in the folder, separated by returns. Then in a loop walk through this list and get the date created and size of each of the files, using the TrFile_GetDateCreated and TrFile_GetFileSize functions.

Set Field [ creationDate ; TrFile_GetDateCreated ( "-Unused" ; gFilePath ) ]
Set Field [ gSize ; TrFile_GetFileSize ( "-Unused" ; gFilePath ) ]

You can calculate the gFilePath parameter from the path of the folder you have listed + the filename from the list.
For an example of a loop script please see the ManageMedia.fmp12 example file that comes with the download of Troi File Plug-in. This shows how to import a whole folder of image files, by using the Listfolder function to get a list of all files in a folder and then importing them one by one. In the example file have a look at the script ‘LOOP: Import the files from the folder’ and the scripts it refers to. You can change this to your own needs, by not importing the files but getting the creation date and file size of them one by one.

How can I detect if a file exists?

Use the TrFile_Exists function introduced in version 3.0.4!

Manipulating files

How can I separate filename and folder from a full path?

If you are using Troi File Plug-in version 14.0 or later, you can simply use the TrFile_GetFileName function to derive the filename (including the extension) from a filepath. If you are using an older version of Troi File Plug-in use the following:
Let’s say the full path is present in a global text field gFullPath. Then in a script you can use these calculations to split it out:

Set Field [ FileName ; Middle ( gFullPath ; Position ( gFullPath ;
    If ( Abs ( Get ( CurrentPlatform ) ) = 1 ; ":" ; "\" ) ;
    Length ( gFullPath ) ; -1 ) + 1 ; Length ( gFullPath ) ) ]
Set Field [ Folder ; Left ( gFullPath ; Length ( gFullPath ) - Length ( FileName ) ) ]

When deleting a file we get a $$-47 error. What is going wrong?

This is the file is busy error. The file is probably opened by an other application.

Can the File Plug-in link to documents outside the database for example Microsoft Word documents?

Yes, use the TrFile_Launch function for this. Store the name of the external file in the database, including the path information. To keep this flexible you should consider to store the path to the file in a separate (global) field:

gPathToWordDocumentsFolder could contain

fileName could for example contain
In the script add this:

Set Field [ gFilePath ; gPathToWordDocumentsFolder & fileName ]
Set Field [ gErrorCode ; TrFile_Launch ( "-unused" ; gFilePath ) ]

This will launch the file specified by gFilePath with its application.

Is there a way of using 'TrFile_MoveFile' to move files from one disk to a folder of a server?

Use the switch “-AllowDifferentVolumes” with the TrFile_MoveFile function to allow the move of a file between different volumes (disks). This switch was introduced in version 10 of Troi File Plug-in. Note that moving a big file across disks may take more time.

Can the Troi File Plug-in rename a file without too much scripting? If so, what function do you use?

You can do this using the TrFile_MoveFile function. See the Online Help of Troi File Plug-in, which shows this example:

Renaming a file:

assume your C disk already contains a file “Testtext.txt”. We assume that a global number field gErrorCode is defined. Create the following script:

Set Field [ gErrorCode ; TrFile_MoveFile ( "-Unused" ; "C:\Testtext.txt" ; "C:\NewName.txt" ) ]

This script will move (rename) the file “Testtext.txt” to the “NewName.txt” file in the same directory. Note that on Mac OS the paths will be like:
“Work Disk:NewName.txt”.

Can Troi File Plug-in work with UNC paths?

In some cases Troi File Plug-in can use UNC paths (like: \\Server\\share), as underlying Windows calls support it (UNC paths won’t work on macOS). But in general Troi File Plug-in needs full paths.
The following are valid paths that Troi File Plug-in can work with on macOS:

“” (full path)


“filemac:/Diskname/folder/” (Filemaker style path)

From version 12 you can also use:

“/Diskname/folder/” (implicit FileMaker style path)

and from version 13:

“smb://” (SMB style path. More info here.)

On Windows you can use:

“C:\directory\” (full path)


“filewin:/C:/directory/” (Filemaker style path)

and from version 12 also:

“/C:/directory/” (implicit FileMaker style path)


On Windows the TrFile_LaunchFile command does not launch a file with a specific extension. How can I fix this?

It may be that your system is not configured to launch this filetype.
You can check this as follows (these instructions are for Windows 10):
In Settings open “System”. Select “Default apps” and then “Choose default applications by file type”. Search the extension that does not work and make sure to choose the default application you want to open it with.

Drag and Drop

When I setup a drop zone the Drag and Drop functionality no longer works correctly when the layout is zoomed in. How do I adjust the field bounds of the drop zone for zooming?

Use FileMaker’s Get(WindowZoomLevel) function to find out the zoom level. Then multiply the field bounds by the zoom level divided by 100.

Server-side use

The TrFile_SelectFileDialog command returns a $$-4251 error code when I use it server-side. What gives?

Server-side and web-side plug-ins can’t make use of a graphic user interface (GUI). This makes sense as FileMaker Server is running without a user anyway. Practically this means that plug-ins can’t show dialog boxes etc. Functions that require a graphic user interface will return error $$-4251 kErrNotAvailableOnServer = This function is not available on FileMaker Server or not web compatible, as it involves graphic user interface.

Troi File Plug-in returns an 'Acces denied' error when I use its functions in a server-side script. How can I fix this?

When you run a plug-in server-side, it will run in the context of the FileMaker Server application. FileMaker Server runs in a non-logged-in state and does not have permissions. As long as you are targeting files or folders inside the Server Documents folder you should be OK, but outside of that you are likely to get permission errors. Opening read/write to everyone on the files/folders you are targeting may help then.

Troi File Plug-in returns $$-120 when I target files or folders on a remote disk in a server-side script. How can I fix this?

$$-120 dirNFErr = Directory not found. You may need to mount the external drive explicitly for FileMaker Server, as this runs as a separate process. You can use the Mount Disk script step or TrFile_MountDisk function for this in your server-side script.


Can you make alias or shortcut files with the Troi File Plug-in?

Yes, use the TrFile_CreateAlias function for this (introduced in version 8.5).

I'm on Windows and I get an error code. When I checked your OSErrrs database I saw that the error code is a Mac error code. How can this be?

We try to make cross-platform error handling simpler by translating error codes on Windows to the corresponding error code on Mac OS. For example on Windows you might get the error “$$-43” which means “File not found”.
NOTE It is still possible to get Windows errors, as we can only translate the error codes that are expected.

Why can't I find a close command for the files that the Troi File Plug-in creates, reads or writes?

The Troi File Plug-in automatically closes the files after each function that accesses a file. This affects TrFile_GetContents, TrFile_SetContents, TrFile_AppendContents, TrFile_InsertContents and TrFile_Substitute.

Is it possible to get the 'File Info' for a given file with the File Plug-in? I'm hoping to be able to get the information from the 'Info & Comments' window on the Mac or the 'Properties' window on the PC.

Yes, from version 3.0.5 you can get this data from “Get Info” with Troi File Plug-in. Use this function:

TrFile_GetFileAttribute ( "-FinderCommentAttr" ; TheFile )

See the example file Attribute.fmp12. You can also use TrFile_GetMetaData to get the data that is embedded in the file itself. See in Photoshop the IPTC data under File→File Info, and also the example file IPTC_XMP_Metadata.fmp12.

Other questions?

If your question is not answered here, please look in the documentation that comes with the plug-in. If you have suggestions please email a FAQ suggestion.