Move or rename file or folder
the file or folder
source to the current folder.
not preserve the archive attribute of
source to the file or folder
destination are in the same location, then
destination. To rename a file or folder when moving it,
destination a different name from
source and specify only one file or folder for
source is a folder, then
destination must be a
source is a folder or is capable of specifying
multiple files and
destination does not exist, then
specified file or folder and returns a status of
status = movefile(___)
1 if the
operation is successful. Otherwise,
0. You can use this syntax with any of the input argument
combinations in the previous syntaxes.
Move files and folders to the current folder by omitting the destination input.
Create two folders: the first,
myfiles, containing the file
myfile1.m, and the second,
myotherfiles, containing the file
mkdir myfiles movefile myfile1.m myfiles mkdir myotherfiles movefile myfile2.m myotherfiles
myfile1.m to the current folder. Since a destination is not specified, MATLAB® assumes the destination is the current folder.
Set the current folder to
myotherfiles and its contents to the current folder.
cd myfiles movefile ../myotherfiles
Move files and subfolders whose names begin with
my from the current folder to the folder
newFolder previously does not exist.
movefile my* newFolder
Create the folder
myoldfolder, and then rename it to
mkdir myoldfolder movefile myoldfolder mynewfolder
Move the file
myfile1.m from the current folder to the read-only folder
Create the read-only folder
mkdir restricted fileattrib restricted -w
Move the file
myfile1.m. A status of 0 shows the copy was unsuccessful.
status = movefile('myfile1.m','restricted'); status
status = logical 0
Move 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] = movefile('myfile1.m','restricted','f'); status
status = logical 1
message = 0x0 empty char array
messageId = 0x0 empty char array
source— File or folder to move
File or folder to move, specified as a character vector or string scalar. To move multiple files or folders, use wildcards (*).
source can be an absolute or relative path when moving
local files or folders. However, to move files and folders at a remote
source must contain a full path specified as a
uniform resource locator (URL). For more information, see Work with Remote Data.
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 cannot include wildcards (*).
destination is local, it can be specified as an
absolute or relative path. If
destination is remote, it
must contain a full path specified as a URL. For more information, see Work with Remote Data.
destination is a string, enclose all the inputs
in parentheses. For example,
status— Move status
Move 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,
*.*on UNIX platforms matches only files that have an extension
Behavior changed in R2020a
Starting in R2020a, on UNIX® platforms, the wildcard expression
*.* no longer
matches folders or files without an extension. In previous releases, the expression
matches folders or files regardless of extension, including files without an
extension. This change of behavior does not apply to Microsoft®