Files.CopyFile
--------------

Copies files and folders without user interface.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [Files](component_Files.md) | [2.8](newinversion28.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "Files.CopyFile"; SourcePath; DestPath { ; Overwrite; SkipSourcePermissionErrors; ProgressTitle } ) 

**MBS**( **"Files.CopyFile";** /\* Copies files and folders without user interface. \*/  
**$SourcePath**; /\* The native path to the file or folder to be copied.e.g. "/Users/John/Desktop/test.txt" \*/   
**$DestPath**; /\* The native path to the destination folder or file.e.g. "/Users/John/Desktop/Backup/" \*/   
**$Overwrite**; /\* Optional; Mac only: Whether to allow overwriting existing files. Default is off. Pass 1 to enable and 0 to disable.  
(ignored on other platforms)e.g. 1 \*/   
**$SkipSourcePermissionErrors**; /\* Optional; Mac only: Whether to skip files with permission errors. Default is off. Pass 1 to enable and 0 to disable.e.g. 1 \*/   
**$ProgressTitle**) /\* Optional; Title for the progress window.  
For Windows only and the text may not be visible in your version of Windows.e.g. "Copying FileMake files" \*/ 

### Parameters

| Parameter | Description | Example | Flags |
|---|---|---|---|
| SourcePath | The native path to the file or folder to be copied. | "/Users/John/Desktop/test.txt" |  |
| DestPath | The native path to the destination folder or file. | "/Users/John/Desktop/Backup/" |  |
| Overwrite | Mac only: Whether to allow overwriting existing files. Default is off. Pass 1 to enable and 0 to disable.   (ignored on other platforms) | 1 | Optional |
| SkipSourcePermissionErrors | Mac only: Whether to skip files with permission errors. Default is off. Pass 1 to enable and 0 to disable. | 1 | Optional |
| ProgressTitle | Title for the progress window.   For Windows only and the text may not be visible in your version of Windows. | "Copying FileMake files" | Optional |

### Result

Returns OK or error message.

### Description

Copies files and folders without user interface.  
SourcePath and DestPath must be valid and exist. So pass destination folder for the destination.   
This function needs a native path. Please use [Path.FileMakerPathToNativePath](PathFileMakerPathToNativePath.md) function in order to convert a FileMaker style path to a native path.  
  
The Linux implementation copies file to dest. You need to have read permissions for source file. We try to preserve extended attributes and file permissions.  
  
On Windows the 5th parameter can be 1 to use alternative copy function from Windows. This one is for copying one file only, but may be more successful in some cases.  
### Examples

Copy a file:

 MBS ( "Files.CopyFile"; "/Users/cs/Desktop/test.pdf"; "/Users/cs/Desktop/copy.pdf")  
Copy file on Windows with alternative copy method:

 MBS ( "Files.CopyFile"; "D:\\Arbeitsunterlagen\\Problemloesungsbericht\_SDAG\_WM.xlsx"; "D:\\Files\_for\_ZIP/CC\_\_8D\_1997\_01\_02\_\_LU\_53145345\_\_2\_97.xlsx"; 0; 0; 1)  
Copy a file from desktop to a network volume:

 MBS ( "Files.CopyFile"; "C:\\Users\\Christian\\Desktop\\test.mov"; "Z:\\Files\\test.mov")  
### See also

- [Files.CopyFiles](FilesCopyFiles.md)
- [Files.MoveFile](FilesMoveFile.md)
- [Files.ReadAndWriteFile](FilesReadAndWriteFile.md)
- [Files.ReadFile](FilesReadFile.md)
- [Path.FileMakerPathToNativePath](PathFileMakerPathToNativePath.md)

### Release notes

- **Version 12.0**
    - Added workaround for [Files.MoveFile](https://www.mbsplugins.eu/FilesMoveFile.shtml) and [Files.CopyFile](https://www.mbsplugins.eu/FilesCopyFile.shtml) when it fails with MAX\_PATH error.
- **Version 10.0**
    - Added [Files.CopyFiles](https://www.mbsplugins.eu/FilesCopyFiles.shtml) function.
    - Fixed an issue for [Files.MoveFile](https://www.mbsplugins.eu/FilesMoveFile.shtml) and [Files.CopyFile](https://www.mbsplugins.eu/FilesCopyFile.shtml) where unability to move an old file to trash caused a problem on AFP volumes.
    - Fixed crashes with [Files.CopyFiles](https://www.mbsplugins.eu/FilesCopyFiles.shtml) function with invalid paths.
- **Version 8.5**
    - Improved error handling for [Files.CopyFile](http://www.mbsplugins.eu/FilesCopyFile.shtml) and [Files.MoveFile](http://www.mbsplugins.eu/FilesMoveFile.shtml).
    - Rewrote [Files.CopyFile](http://www.mbsplugins.eu/FilesCopyFile.shtml) and [Files.MoveFile](http://www.mbsplugins.eu/FilesMoveFile.shtml) for Mac/iOS to better overwrite files.
- **Version 7.0**
    - Added progress window option to [Files.CopyFile](http://www.mbsplugins.eu/FilesCopyFile.shtml) and [Files.MoveFile](http://www.mbsplugins.eu/FilesMoveFile.shtml) for Windows.

### Example Databases

- [Files/FileOperation](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Files/FileOperation.shtml#4ScriptAnchor_)

### Blog Entries

- [MBS Plugin Advent calendar: 12 - Files](https://www.mbsplugins.de/archive/2023-12-12/MBS_Plugin_Advent_calendar_12_/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 11.6pr4](https://www.mbsplugins.de/archive/2021-12-22/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [Recursive Folder Copy Script](https://www.mbsplugins.de/archive/2021-11-12/Recursive_Folder_Copy_Script/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin 11.1](https://www.mbsplugins.de/archive/2021-03-16/MBS_FileMaker_Plugin_111/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 9.6pr2](https://www.mbsplugins.de/archive/2019-12-10/MBS_FileMaker_Plugin_version_9/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 8.5pr7](https://www.mbsplugins.de/archive/2018-11-14/MBS_FileMaker_Plugin_version_8/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 8.5pr2](https://www.mbsplugins.de/archive/2018-10-12/MBS_FileMaker_Plugin_version_8/monkeybreadsoftware_blog_filemaker)
- [Comparing Base Elements Plugin to MBS FileMaker Plugin](https://www.mbsplugins.de/archive/2017-10-24/Comparing_Base_Elements_Plugin/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 7.0pr3](https://www.mbsplugins.de/archive/2017-01-13/MBS_FileMaker_Plugin_version_7/monkeybreadsoftware_blog_filemaker)
- [Tip of the day: Mount drive on FileMaker Server](https://www.mbsplugins.de/archive/2016-07-05/Tip_of_the_day_Mount_drive_on_/monkeybreadsoftware_blog_filemaker)

This function checks for a license.

Created 18th August 2014 , last changed 3th January 2020

  
[Files.CanOpenFile](FilesCanOpenFile.md) - [Files.CopyFiles](FilesCopyFiles.md)

[HTML Version](FilesCopyFile.shtml)