Moves (or renames) a file from one location to another.
TrFile_MoveFile ( switches ; sourceFilePath ; destinationFilePath )
|switches||modifies the behavior of the function|
|sourceFilePath||the path to the file to move|
|destinationFilePath||the path where the file must be moved to|
Switches can be empty or this:
|-AllowDifferentVolumes||allow the move between different volumes (disks). Moving a big file across disks may take more time.|
Data type returned
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 moved|
|$$-43||fnfErr||Source file not found, or destination directory does not exist|
|$$-48||dupFNErr||Destination file already exists|
|$$-1303||diffVolErr||The 2 files are on different volumes|
|$$-4254||returnInPathErr||The path contains an illegal return character|
|$$-1||genericErr||The file could not be moved|
Other errors may be returned.
Troi File Plug-in 1.1
FileMaker Pro 13 to 17
TIP: You can also use this function to rename a file
See also the functions TrFile_SelectFileDialog and TrFile_SaveFileDialog to get a filePath for a 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 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:\New\L2000_01.TXT” (Windows) or “Mac HD:New:Log 2000_01” (Mac). In a script add the following scriptstep:
Set Field [ gErrorCode ; TrFile_MoveFile ( "-Unused" ; gSourceFilePath ; gDestFilePath ) ]
This will move the source file to the path indicated in the gDestFilePath.
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”.
Related script step