| MATLAB Function Reference | ![]() |
In the Current Directory browser, select Edit > Copy, then Paste. See details.
copyfile('source','destination')
copyfile('source','destination','f')
[status,message,messageid] = copyfile('source','destination','f')
copyfile('source','destination') copies the file or directory, source (and all its contents) to the file or directory, destination, where source and destination are the absolute or relative pathnames for the directory or file. If source is a directory, destination cannot be a file. If source is a directory, copyfile copies the contents of source, not the directory itself. To rename a file or directory when copying it, make destination a different name than source. If destination already exists, copyfile replaces it without warning. Use the wildcard * at the end of source to copy all matching files. Note that the read-only and archive attributes of source are not preserved in destination.
copyfile('source','destination','f') copies source to destination, regardless of the read-only attribute of destination.
[status,message,messageid] = copyfile('source','destination','f') copies source to destination, returning the status, a message, and the MATLAB® error message ID (see error and lasterror). Here, status is 1 for success and 0 for error. Only one output argument is required and the f input argument is optional.
The * wildcard in a path string is supported. Current behavior of copyfile differs between the UNIX® and Windows® platforms when using the wildcard * or copying directories. (UNIX is a registered trademark of The Open Group in the United States and other countries).
The timestamp given to the destination file is identical to that taken from the source file.
To make a copy of a file myfun.m in the current directory, assigning it the name myfun2.m, type
copyfile('myfun.m','myfun2.m')To copy myfun.m to the directory d:/work/myfiles, keeping the same filename, type
copyfile('myfun.m','d:/work/myfiles')To copy all files in the directory myfiles whose names begin with my to the directory newprojects, where newprojects is at the same level as the current directory, type
copyfile('myfiles/my*','../newprojects')In this example, all files and subdirectories in the current directory's myfiles directory are copied to the directory d:/work/myfiles. Note that before running the copyfile function, d:/work does not contain the directory myfiles. It is created because myfiles is appended to destination in the copyfile function:
[s,mess,messid]=copyfile('myfiles','d:/work/myfiles')
s =
1
mess =
''
messid =
''The message returned indicates that copyfile was successful.
Copy myfile.m from the current directory to d:/work/restricted, where restricted is a read-only directory:
copyfile('myfile.m','d:/work/restricted','f')After the copy, myfile.m exists in d:/work/restricted.
cd, delete, dir, fileattrib, filebrowser, fileparts, mkdir, movefile, rmdir
![]() | convn | copyobj | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |