Files.ReadAndWriteFile
----------------------

Reads a file and writes it elsewhere.

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

MBS( "Files.ReadAndWriteFile"; SourcePath; DestPath ) 

**MBS**( **"Files.ReadAndWriteFile";** /\* Reads a file and writes it elsewhere. \*/  
**$SourcePath**; /\* The native path to the file to be copied.e.g. "/Users/John/Desktop/test.txt" \*/   
**$DestPath**) /\* The native path to the target file to write.e.g. "/Users/John/Desktop/Backup/" \*/ 

### Parameters

| Parameter | Description | Example |
|---|---|---|
| SourcePath | The native path to the file to be copied. | "/Users/John/Desktop/test.txt" |
| DestPath | The native path to the target file to write. | "/Users/John/Desktop/Backup/" |

### Result

Returns OK or error.

### Description

Reads a file and writes it elsewhere.  
The data is read in 10 MB blocks and then written to the destination file.  
Usually you may use [Files.CopyFile](FilesCopyFile.md) using OS routines, but sometimes clients want a replacement.  
Always overwrites files.  
Does not copy metadata on purpose.  
### Examples

Copy a file:

 MBS ( "Files.ReadAndWriteFile"; "/Users/cs/Desktop/test.dmg"; "/Users/cs/Desktop/test2.dmg" )  
### See also

- [Files.CopyFile](FilesCopyFile.md)

### Example Databases

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

### Blog Entries

- [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)

This function is free to use.

Created 16th February 2021 , last changed 4th August 2023

  
[Files.PrintFile](FilesPrintFile.md) - [Files.ReadFile](FilesReadFile.md)

[HTML Version](FilesReadAndWriteFile.shtml)