Products & Services Solutions Academia Support User Community Company

Learn more about MATLAB   

movefile - Move file or folder

Graphical Interface

As an alternative to the movefile function, use the Current Folder browser.

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 an * 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

Move the file myfiles/myfunction.m to the current folder:

movefile('myfiles/myfunction.m')

Move projects/myfiles and its contents to the current folder, when the current folder is projects/testcases:

movefile('../myfiles')

Renaming a File in the Current Folder

Rename myfunction.m to oldfunction.m:

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

Using a Wildcard to Move All Matching Files

Move all files in the folder myfiles, whose names begin with my, to the current folder:

movefile('myfiles/my*')

Moving a File to a Different Folder

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

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

Moving a Folder Down One Level

Move the folder projects/testcases and all its contents down a level in projects to projects/myfiles:

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

Moving a File to 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* mistyped as nex* and no items in the current folder start with nex*:

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

s =
     0

mess =

A duplicate filename exists, or the file cannot be found.

messid =

MATLAB:MOVEFILE:OSError

See Also

cd, copyfile, delete, dir, fileattrib, ls, mkdir, rmdir

Managing Files in MATLAB

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS