Move File |
Moves (or renames) a file from one location to another.
Syntax
Move File [ Select ; Result (error) ; Source filePath ;
Destination filePath ; Allow different volumes ]
Options
Select entire contents | replaces the entire contents of a field with the result. If not checked the result replaces the currently selected portion of the field |
Result (error) | an error code |
Source filePath | the path to the file to move |
Destination filePath | the path where the file must be moved to |
Allow different volumes | allows the move of the file 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 9.0
Compatibility
FileMaker Pro 16 to FileMaker Pro 2023
Considerations
TIP: You can also use this function to rename a file
See also the script steps Show Select File Dialog and Show Save File Dialog” to get a filePath for a file.
When the step returns the error code $$-1303, you can use the checkbox Allow Different Volumes.
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:
Move File [ Select ; gErrorCode ; 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:
Move File [ Select ; gErrorCode ; "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 macOS the paths will be like: “Work Disk:NewName.txt”.
Related script steps
Copy File |
Create File |
Move Folder |
Show Save File Dialog |
Show Select File Dialog |
Related function
TrFile_MoveFile |
Related topics
Troi File Plug-in online help (overview)