Skip to main content

TrFile_MoveFile (function reference)

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

TrFile_MoveFile

Moves (or renames) a file from one location to another.

SyntaxFunction badge

TrFile_MoveFile ( switches ; sourceFilePath ; destinationFilePath )

Parameters

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

Switches can be empty or this:

-AllowDifferentVolumes allow the move between different volumes (disks). Moving a big file across disks may take more time.

Returned Result

Data type returned

Error code

Result

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.

Originated in

Troi File Plug-in 1.1

Compatibility

FileMaker Pro 17 to FileMaker Pro 21 (2024)

Considerations

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.

Example

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.

Example 2

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

Used in example file

FileManipulation.fmp12

Related functionsFunction badge

TrFile_CopyFile
TrFile_CreateFile
TrFile_SaveFileDialog
TrFile_SelectFileDialog

Related script stepScript step badge

Move File

Related topics

Troi File Plug-in online help (overview)


Online Help Page for Troi File Plug-in for 17 to 2024 –> TrFile_MoveFile (filep4262) 2024-0604 19:26:56