Products & Services Industries Academia Support User Community Company

Learn more about MATLAB   

copyfile - Copy file or folder

GUI Alternatives

Copy files and folders using the Current Folder browser.

Syntax

copyfile('source','destination')
copyfile('source','destination','f')
[status] = copyfile(...)
[status, message] = copyfile(...)
[status,message,messageid] = copyfile(...)

Description

copyfile('source','destination') copies the file or folder named source to the file or folder destination. The values for 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.

Remarks

Examples

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:ReadOnly

Copy 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 =
     ''

See Also

cd, delete, dir, fileattrib, filebrowser, fileparts, mkdir, movefile, rmdir

User Guide topics:

  


Free MATLAB Interactive Kit

Explore how to use MATLAB to make advancements in engineering and science.


Download free kit

Trials Available

Try the latest version of MATLAB and other MathWorks products.


Get trial software
 © 1984-2010- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS