Quantcast

Documentation Center

  • Trial Software
  • Product Updates

movefile

Move file or folder

Syntax

movefile('source')
movefile('source','destination')
movefile('source','destination','f')
[status,message,messageid] = movefile(___)

Description

movefile('source') moves the file or folder named source to the current folder, where source is the absolute or relative path name for the folder or file. To move multiple files or folders, use one or more wildcard characters (*) after the last file separator in source. The source argument permits a wildcard character in a path string. movefile does not preserve the archive attribute of source.

movefile('source','destination') moves the file or folder named source to the location destination, where source and destination are the absolute or relative paths for the folder or file. To move multiple files or folders, you can use one or more wildcard characters (*) after the last file separator in source. You cannot use a wildcard character in destination. To rename a file or folder when moving it, make destination a different name than source, and specify only one file for source. When source and destination have the same location, movefile renames source to destination.

movefile('source','destination','f') moves the file or folder named source to the location destination, regardless of the read-only attribute of destination.

[status,message,messageid] = movefile(___) moves the file or folder named source to the location destination, returning the status, a message, and the MATLAB® message ID. Here, status is logical 1 for success or logical 0 for error. movefile requires only one output argument.

Examples

Moving a File to the Current Folder

Assuming myfiles is a subfolder within the current folder, move the file myfunction.m to the current folder:

movefile('myfiles/myfunction.m')

Assuming projects/testcases is the current folder, move projects/myfiles and its contents to the current folder:

movefile('../myfiles')

Renaming a File in the Current Folder

In the current folder, rename myfunction.m to oldfunction.m:

movefile('myfunction.m','oldfunction.m')

Using a Wildcard to Move All Matching Files

Assuming myfiles is a subfolder of the current folder, move all files whose names that begin with my from the myfiles folder, to the current folder:

movefile('myfiles/my*')

Moving a File to a Different Folder

Assuming projects and the current folder are at the same level, move the file myfunction.m from the current folder to the folder projects:

movefile('myfunction.m','../projects')

Moving a Folder Down One Level

Assuming projects is a subfolder of the current folder, move the folder projects/testcases and all its contents down a level in projects into projects/myfiles:

movefile('projects/testcases','projects/myfiles/')

Moving a File to a Read-Only Folder and Renaming the File

Move the file myfile.m from the current folder to d:/work/restricted, assigning it the name test1.m, where restricted is a read-only folder:

movefile('myfile.m','d:/work/restricted/test1.m','f')

The read-only file myfile.m is no longer in the current folder. The file test1.m is in d:/work/restricted and is read only.

Returning Status When Moving Files

Move all files in the folder myfiles whose names start with new to the current folder, when there is an error. You mistype new* as nex* and no items in the current folder start with nex*:

[s,mess,messid] = movefile('myfiles/nex*') 

s =
     0

mess =

No matching files were found.

messid =

MATLAB:MOVEFILE:FileDoesNotExist

See Also

| | | | | | |

Was this topic helpful?