| MATLAB® | ![]() |
As an alternative to the movefile function, you can use the Current Directory browser to move files and directories.
movefile('source')
movefile('source','destination')
movefile('source','destination','f')
[status,message,messageid]=movefile('source','destination','f')
movefile('source') moves the file or directory named source to the current directory, where source is the absolute or relative path name for the directory or file. To move multiple files or directories, you can use one or more wildcard characters * after the last file separator in source. Note that the archive attribute of source is not preserved.
movefile('source','destination') moves the file or directory named source to the location destination, where source and destination are the absolute or relative paths for the directory or files. To move multiple files or directories, 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 directory when moving it, make destination a different name than source, and specify only one file for source.
movefile('source','destination','f') moves the file or directory named source to the location destination, regardless of the read-only attribute of destination.
[status,message,messageid]=movefile('source','destination','f') moves the file or directory named source to the location destination, returning the status, a message, and the MATLAB error message ID (see error and lasterror). Here, status is logical 1 for success or logical 0 for error. Only one output argument is required and the f input argument is optional.
You can use the * (wildcard character) in a path string.
To move the file myfiles/myfunction.m to the current directory, type
movefile('myfiles/myfunction.m')If the current directory is projects/testcases and you want to move projects/myfiles and its contents to the current directory, use ../ in the source path to navigate up one level to get to the directory.
movefile('../myfiles')To move all files in the directory myfiles whose names begin with my to the current directory, type
movefile('myfiles/my*')To move the file myfunction.m from the current directory to the directory projects, where projects and the current directory are at the same level, type
movefile('myfunction.m','../projects')This example moves the a directory down a level. For example to move the directory projects/testcases and all its contents down a level in projects to projects/myfiles, type
movefile('projects/testcases','projects/myfiles/')The directory testcases and its contents now appear in the directory myfiles.
Move the file myfile.m from the current directory to d:/work/restricted, assigning it the name test1.m, where restricted is a read-only directory.
movefile('myfile.m','d:/work/restricted/test1.m','f')The read-only file myfile.m is no longer in the current directory. The file test1.m is in d:/work/restricted and is read only.
This example aims to move to the current directory all files in the directory myfiles whose names start with new. However, new* is mistyped as nex*. As a result, movefile is unsuccessful because no files are found that start with nex, and the status, message, and messageid returned indicate this:
[s,mess,messid]=movefile('myfiles/nex*')
s =
0
mess =
A duplicate filename exists, or the file cannot be found.
messid =
MATLAB:MOVEFILE:OSErrorcd, copyfile, delete, dir, fileattrib, filebrowser, ls, mkdir, rmdir
Managing Files and Working with the Current Directory
![]() | move | movegui | ![]() |
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |