Desktop Tools and Development Environment Previous page   Next Page

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,

  1. Select New from the context menu or File menu and then select the type of file to create.
  1. An icon for that file type, for example, an M-file icon , with the default name Untitledn, appears at the end of the list of files shown in the Current Directory browser.

  1. Type over Untitledn with the name you want to give to the new file.
  2. Press Enter or Return.
  1. The file is added.

  1. To enter the contents of the new M-file, open the file--see Opening and Running Files. If you created the file using the context menu, the new file opens in the Editor/Debugger with a template for writing an M-file function.

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,

  1. Click the New Folder button in the Current Directory browser toolbar, or select New -> Folder from the context menu.
  1. An icon, with the default name NewFoldern appears at the end of the list of files shown in the Current Directory browser.

  1. Type over NewFoldern with the name you want to give to the new directory.
  2. Press the Enter or Return key.
  1. The directory is added.

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,

  1. Select the files and directories to remove. Use Shift+click or Ctrl+click to select multiple items.
  2. Right-click and select Cut or Delete from the context menu.
  1. The files and directories are removed.

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:

  1. Select the files or directories to copy. Use Shift+click or Ctrl+click to select multiple items. For a directory, the entire contents are copied, including all subdirectories and files.
  2. Right-click and select Copy from the context menu.
  3. Navigate to the file or directory where you want to paste the items you just copied.
  4. Right-click and select Paste from the context menu.

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')

Previous page  Viewing and Making Changes to Directories Opening and Running Files Next page

© 1994-2005 The MathWorks, Inc.