TrFile_ExchangeFiles (function reference)

By May 15, 2018 May 22nd, 2019 Online Help, Troi File Plug-in
Troi File Plug-in > Functions reference > TrFile_ExchangeFiles
Troi File Plug-in for FileMaker Pro


Exchanges two files on disk

SyntaxFunction badge

TrFile_ExchangeFiles ( switches ; filePath1 ; filePath2 )


switchesmodifies the behavior of the function
filePath1the path to the first file
filePath2the path to the second file


Switches can be empty or this:

-AllowDifferentVolumesallow exchanging of files on different disks. Note that it may take more time to exchange the two files.

Returned Result

Data type returned

Error code


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:

0no errorthe files were exchanged
$$-43fnfErrone (or two) of the files not found
$$-1303diffVolErrthe 2 files are on different volumes

Other errors may be returned.

Originated in

Troi File Plug-in 10.0


FileMaker Pro 14 to 18


You can use the TrFile_ExchangeFiles function to quickly replace a file with an updated file.
When the function returns the error code $$-1303, you can use the switch -AllowDifferentVolumes.


We assume that in your FileMaker file the following fields are defined:

  gErrorCode		Global, number
  gFilePath1		Global, text
  gFilePath2		Global, text

gFilePath1 and gFilePath2 should contain the path to existing files, for example “D:\Logs\Current.TXT” and
“D:\Work\Updated.TXT”. In a script add the following script steps:

Set Variable [ $ErrorCode ; TrFile_ExchangeFiles ( "-Unused" ; gFilePath1 ; gFilePath2 ) ]
Set Field [ gErrorCode ; $ErrorCode // save the error code too ]

This will (quickly) exchange the two files. After this step the file “D:\Logs\Current.TXT” will have the contents of “D:\Work\Updated.TXT” and vice versa.

Example 2

In a script add the following script stept:

Set Field [ gErrorCode ; TrFile_ExchangeFiles ( "-AllowDifferentVolumes" ; 
						"Update Disk:NewData.fmp12" ; 
						"Work Disk:DataDB.fmp12" ) ]

This will exchange the two files, even if the files are on 2 different volumes (disks).

Related functionsFunction badge


Related script stepsScript step badge

Copy File
Delete File
Exchange Files
Move File

Related topics

Troi File Plug-in online help (overview)

Online Help Page for Troi File Plug-in for 14 to 18 –> TrFile_ExchangeFiles (filep4317) 2019-0522 16:36:46