Skip to main content

TrFile_CopyFile (function reference)

By June 1, 2024June 4th, 2024Online Help, Troi File Plug-in
Troi File Plug-in for FileMaker Pro


Copies a file to the specified path.

SyntaxFunction badge

TrFile_CopyFile ( switches ; sourceFilepath ; destinationFilePath )


switches reserved for future use, leave empty or set to "-Unused"
sourceFilePath the path to the file to copy
destinationFilePath the path where the file must be copied to

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 file was copied
$$-43 fnfErr Source file not found, or destination directory does not exist
$$-48 dupFNErr Destination file already exists
$$-4254 returnInPathErr The path contains an illegal return character
$$-1 genericErr The file could not be copied

Other errors may be returned.

Originated in

Troi File Plug-in 1.1


FileMaker Pro 17 to FileMaker Pro 21 (2024)


You can use FileMaker styled paths, like “filemac:/MacHD/folderA/test.txt”.
Use the TrFile_DeleteFile to delete a file first if it exists. See also the function TrFile_SaveFileDialog to get a FileSpec for 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_CopyFile ( "-Unused" ; "C:\Testtext.txt" ; "D:\MyFiles\TestDupl.txt" ) ]

This script will copy the file “Testtext.txt” to the “TestDupl.txt” file in directory “MyFiles” on the D: disk. On macOS the paths will be of the form “Mac HD:MyFiles:TestDupl.txt”.

Example 2

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

  gErrorCode		Global, number
  gSourceFilePath	Global, text
  gDestFilePath		Global, text

gSourceFilePath should contain the path to an existing file, for example “D:\Logs\Log01.TXT” (Windows) or “Mac HD:Logs:Log 1” (Mac). gDestFilePath should contain the path to the destination and should not exist, for example “D:\Logs\L2000_01.TXT” (Windows) or “Mac HD:Logs:Log 2000_01” (Mac). In a script add the following script step:

Set Field [ gErrorCode ; TrFile_CopyFile ( "-Unused" ; gSourceFilePath ;  gDestFilePath ) ]

This will copy the source file to the path indicated in the gDestFilePath.

Used in example file


Related functionsFunction badge


Related script stepScript step badge

Copy File

Related topics

Troi File Plug-in online help (overview)

Online Help Page for Troi File Plug-in for 17 to 2024 –> TrFile_CopyFile (filep4210) 2024-0604 19:23:39