Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

movefile

Move file or folder

Syntax

movefile source
movefile source destination
movefile source destination f
status = movefile(___)
[status,msg] = movefile(___)
[status,msg,msgID] = movefile(___)

Description

example

movefile source moves the file or folder source to the current folder. movefile does not preserve the archive attribute of source.

example

movefile source destination moves the file or folder source to the file or folder destination. If source and destination are in the same location, movefile renames source to destination. To rename a file or folder when moving it, make destination a different name than source, and specify only one file or folder for source.

If source is a folder, destination must also be a folder. If source is a folder or specifies multiple files and destination does not exist, movefile creates destination.

example

movefile source destination f moves source to destination, even when destination is not writable. The state of the read/write attribute for destination does not change.

example

status = movefile(___) moves the specified file or folder and returns a status of 1 if the operation is successful. Otherwise, it returns 0. You can use this syntax with any of the input argument combinations in the previous syntaxes.

example

[status,msg] = movefile(___) also returns the message text for any warning or error that occurs. You can use this syntax with any of the input argument combinations in the previous syntaxes.

example

[status,msg,msgID] = movefile(___) also returns the message ID for any warning or error that occurs. You can use this syntax with any of the previously defined input arguments.

Examples

collapse all

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 myfile2.m.

mkdir myfiles
movefile myfile1.m myfiles
mkdir myotherfiles
movefile myfile2.m myotherfiles

Move myfile1.m to the current folder. Since a destination is not specified, MATLAB® assumes the destination is the current folder.

movefile myfiles/myfile1.m

Set the current folder to myfiles. Move 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, where newFolder does not exist.

movefile my* newFolder

Create and then rename the folder myoldfolder to mynewfolder.

mkdir myoldfolder
movefile myoldfolder mynewfolder

Move the file myfile1.m from the current folder to the read-only folder restricted.

Create the read-only folder restricted.

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. A status of 1 and an empty message and messageID confirms the copy was successful.

[status,message,messageId] = movefile('myfile1.m','restricted','f');
status
message
messageId
status =

  logical

   1


message =

  0×0 empty char array


messageId =

  0×0 empty char array

Input Arguments

collapse all

File or folder name to copy, specified as a character vector. source can be an absolute or relative path. To copy multiple files or folders, use wildcards (*).

File or folder name to copy to, specified as a character vector. destination can be an absolute or relative path, but cannot include wildcards (*).

Output Arguments

collapse all

Indication of whether the attempt to copy the file or folder is successful, specified as 0 or 1. If the attempt is successful, status is 1. Otherwise, status is 0.

Data Types: logical

Error message, specified as a character vector. If an error or warning occurs, msg contains the message text of the error or warning. Otherwise, msg is empty, ''.

Error message identifier, specified as a character vector. If an error or warning occurs, msgID contains the message identifier of the error or warning. Otherwise, msgID is empty, ''.

Introduced before R2006a

Was this topic helpful?