MATLAB Function Reference |
Graphical Interface
As an alternative to the movefile
function, you can use the Current Directory browser to move files and directories.
Syntax
movefile('source')
movefile('source','destination')
movefile('source','destination','
f
')
[status,message,messageid] = movefile('source','destination','
f
')
Description
movefile('
moves the file or directory named source')
source
to the current directory, where source
is the absolute or relative pathname for the directory or file. Use the wildcard *
at the end of source
to move all matching files. Note that the archive attribute of source
is not preserved.
movefile('
moves the file or directory named source','destination')
source
to the location destination
, where source
and destination
are the absolute or relative pathnames for the directory or files. To rename a file or directory when moving it, make destination
a different name than source
. Use the wildcard *
at the end of source
to move all matching files.
movefile('
moves the file or directory named source','destination','
f
')
source
to the location destination
, regardless of the read-only attribute of destination
.
[status,message,messageid]=movefile
moves the file or directory named ('source','destination','
f
')
source
to the location destination
, returning the status, a message, and the MATLAB error message ID (see error
and lasterr
). Here, status
is 1
for success and is 0
for error. Only one output argument is required and the f
input argument is optional.
The *
wildcard in a path string is supported.
Move Source to Current Directory
To move the file myfiles/myfunction.m to the current directory, type
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 pathname to navigate up one level to get to the directory.
Move All Matching Files by Using a Wildcard
To move all files in the directory myfiles
whose names begin with my to the current directory, type
Move Source to Destination
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
Move Directory Down One Level
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
The directory testcases
and its contents now appear in the directory myfiles
.
Rename When Moving File to Read-Only Directory
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.
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.
Return Status When Moving Files
In this example, all files in the directory myfiles
whose names start with new
are to be moved to the current directory. However, if new*
is accidentally written as nex*
. As a result, the move is unsuccessful, as seen in the status and messages returned:
[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
, filebrowser
, ls
, mkdir
, rmdir
more | movegui |
© 1994-2005 The MathWorks, Inc.