Copy file or folder
copyfile copies the file or folder
source to the current folder. After a successful
copyfile operation, the timestamp for the new file is the
same as the timestamp for
source is a file, then
destination can be a file or a folder.
source is a folder, then
destination must be a folder.
source is a folder or specifies multiple
destination does not exist, then
copyfile attempts to create
specified file or folder and returns a status of
status = copyfile(___)
1 if the
operation is successful. Otherwise,
0. You can use this syntax with any of the input argument
combinations in the previous syntaxes.
myfile1.m from the current folder to the subfolder
mkdir myFolder copyfile myfile1.m myFolder
Create a copy of
myfile1.m in the current folder, assigning it the name
copyfile myfile1.m myfile2.m
Copy files and subfolders with names beginning with
my from the current folder to the folder
newFolder does not already exist.
copyfile my* newFolder
Copy the file
myfile1.m from the current folder to the read-only folder
Create the read-only folder
mkdir restricted fileattrib restricted -w
Copy and rename the file
myfile1.m. A status of 0 shows the copy was unsuccessful.
status = copyfile('myfile1.m', 'restricted'); status
status = logical 0
Copy the file
myfile1.m using the 'f' option to override the read-only status of the destination folder. A status of 1 and an empty
messageId confirm the copy was successful.
[status,message,messageId] = copyfile('myfile1.m', 'restricted', 'f'); status
status = logical 1
message = 0x0 empty char array
messageId = 0x0 empty char array
source— File or folder to copy
File or folder to copy, specified as a character vector or string scalar.
source can be an absolute or relative path. To copy
multiple files or folders, use wildcards (*).
source is a string, enclose all the inputs in
parentheses. For example,
destination— File or folder destination
File or folder destination, specified as a character vector or string
destination can be an absolute or relative path,
but cannot include wildcards.
destination is a string, enclose all the inputs
in parentheses. For example,
status— Copy status
Copy status, indicating if the attempt to move the file or folder is
successful, returned as
1. If the
attempt is successful, the value of
status is 1.
Otherwise, the value is 0.
msg— Error message
Error message, returned as a character vector. If an error or warning occurs,
msg contains the message text of the error or
msg is empty,
msgID— Error message identifier
Error message identifier, returned as a character vector. If an error or warning occurs,
msgID contains the message identifier of the error or
msgID is empty,