| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB |
| Contents | Index |
| Learn more about MATLAB |
Copy files and folders using the Current Folder browser.
copyfile('source','destination')
copyfile('source','destination','f')
[status] = copyfile(...)
[status, message] = copyfile(...)
[status,message,messageid] = copyfile(...)
copyfile('source','destination') copies the file or folder named source to the file or folder destination. source and destination are 1 x n strings. Use full path names or path names relative to the current folder. To copy multiple files or folders, use one or more wildcard characters * after the last file separator in source. You cannot use a wildcard character in destination.
copyfile('source','destination','f') copies source to destination, even when destination is not writable. The state of the read-write attribute for destination does not change. You can use f with any syntax for copyfile.
[status] = copyfile(...) reports the outcome as a logical scalar, status. The value is 1 for success and 0 for failure.
[status, message] = copyfile(...) returns any warning or error message as a string to message. When copyfile succeeds, message is an empty string.
[status,message,messageid] = copyfile(...) returns any warning or error identifier as a string to messageId. When copyfile succeeds, messageId is an empty string.
The timestamp for destination is the same as the timestamp for source.
When source is a folder, destination must be a folder.
When source is a folder and destination does not exist, copyfile creates destination and copies the contents of source into destination.
When source is a folder and destination is an existing folder, copyfile copies the contents of source into destination.
When source is multiple files and destination does not exist, copyfile creates destination.
For behavior not explicitly stated in the description or remarks, copyfile follows the behavior of the operating system copy command. For example, on UNIX platforms, copyfile is like the UNIX command cp -p.
Copy myFun.m from the current folder to d:/work/Projects/, keeping the same file name:
copyfile('myFun.m','d:/work/Projects/')Make a copy of myFun.m in the current folder, assigning the name myFun2.m to it:
copyfile('myFun.m','myFun2.m')Copy all files and subfolders whose names begin with my, from the Projects folder. Copy to the existing folder newProjects, which is at the same level as the current folder:
copyfile('Projects/my*','../newProjects/')Copy the contents of the Projects folder to the d:/work/newProjects folder. Projects is in the current folder. newProjects does not exist.
copyfile('Projects','d:/work/newProjects')Copy myFun.m from the current folder to d:/work/restricted/myFun2.m, where myFun2.m is read-only. Return output to determine success:
[status,message,messageId]=copyfile('myFun.m','d:/work/restricted/myFun2.m')The results show that copyfile failed:
status =
0
message =
Cannot write to destination: d:/work/restricted/myFun2.m. Use the 'f' option to override
messageId =
MATLAB:COPYFILE:ReadOnlyCopy myFun.m from the current folder to d:/work/restricted/myFun2.m, where myFun2.m is read-only. Use 'f' to force the copy, even though myFun2.m is read-only. Return output to determine success:
[status,message,messageId]=copyfile('myFun.m','d:/work/restricted/myFun2.m','f')The results show that copyfile succeeded:
status =
1
message =
''
messageId =
''cd, delete, dir, fileattrib, filebrowser, fileparts, mkdir, movefile, rmdir
User Guide topics:
![]() | convn | copyobj | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |