Desktop Tools and Development Environment |
Creating, Renaming, Copying, and Removing Directories and Files
General Notes
If you have write permission, you can create, copy, remove, and rename MATLAB related files and directories for the directory shown in the Current Directory browser. If you do not have write permission, you can still copy files and directories to another directory, or you can use equivalent functions, such as movefile
.
To run functions whose arguments require the use of a pathname or filename, use the function form rather than the unquoted or command form of the syntax when the pathname or filename includes spaces. For example, the command form
delete my file.m
generates a warning and does not delete my file.m
. Instead use the function form of the syntax:
delete('my file.m')
Creating New Files
To create a new file in the current directory,
Untitledn
, appears at the end of the list of files shown in the Current Directory browser.
Function Alternative. Use the edit
function to create a new M-file or other type of text file in the Editor/Debugger.
Creating New Directories
To create a new directory in the current directory,
NewFoldern
appears at the end of the list of files shown in the Current Directory browser.
NewFoldern
with the name you want to give to the new directory.
Function Alternative. To create a directory, use the mkdir
function. For example,
mkdir newdir
creates the directory newdir
within the current directory.
Renaming Files and Directories
To rename a file or directory, select the item, right-click, and select Rename from the context menu. Type over the existing name with the new name for the file or directory, and press Enter or Return. The file or directory is renamed.
Function Alternative. You can use movefile
to rename a file or directory. For example,
movefile('myfile.m','projectresults.m')
renames myfile.m
to projectresults.m.
Cutting or Deleting Files and Directories
To cut or delete files and directories,
Files and directories you delete from the Current Directory browser go to the Recycle Bin on Windows (or the Trash Can on Macintosh platforms). If you do not want the selected items to go to the Recycle Bin, press Shift+Delete. A confirmation dialog box displays before the items are deleted if you have set that option in your operating system. For example, on Windows, right-click the Recycle Bin, select Properties from the context menu, and then, under the Global tab, select the check box to Display delete confirmation dialog.
Function Alternative. To delete a file, use the delete
function. For example,
delete('d:/mymfiles/testfun.m')
deletes the file testfun.m
. You can recover deleted files if you use the recycle
function or the equivalent preference described in Default Behavior of the Delete Function.
To delete a directory and optionally its contents, use rmdir
. For example,
rmdir('myfiles')
removes the directory myfiles
from the current directory.
Copying and Pasting Files and Directories
Use the Current Directory browser, to copy (or cut) and paste files and directories:
You can also copy and paste files and directories to and from tools outside of MATLAB, such as Windows Explorer. You can use Current Directory browser menu items or keyboard shortcuts, or you can drag the items.
Function Alternative. Use movefile
or copyfile
to cut and paste or to copy and paste files or directories. For example, to make a copy of the file myfun.m
in the current directory, assigning it the name myfun2.m
, type
copyfile('myfun.m','myfun2.m')
Viewing and Making Changes to Directories | Opening and Running Files |
© 1994-2005 The MathWorks, Inc.