Skip to main content

TrFile_ExchangeFiles (function reference)

By June 1, 2024June 4th, 2024Online 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 )


switches modifies the behavior of the function
filePath1 the path to the first file
filePath2 the path to the second file


Switches can be empty or this:

-AllowDifferentVolumes allow 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:

0 no error the files were exchanged
$$-43 fnfErr one (or two) of the files not found
$$-1303 diffVolErr the 2 files are on different volumes

Other errors may be returned.

Originated in

Troi File Plug-in 10.0


FileMaker Pro 17 to FileMaker Pro 21 (2024)


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).

Used in example file


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 17 to 2024 –> TrFile_ExchangeFiles (filep4317) 2024-0604 19:45:17