rmdir - Remove directory

Graphical Interface

As an alternative to the rmdir function, use the delete feature in the Current Directory Browser.

Syntax

rmdir('dirname')
rmdir('dirname','s')
[status, message, messageid] = rmdir('dirname','s')

Description

rmdir('dirname') removes the directory dirname from the current directory. If the directory is not empty, you must use the s argument. If dirname is not in the current directory, specify the relative path to the current directory or the full path for dirname.

rmdir('dirname','s') removes the directory dirname and its contents from the current directory. This removes all subdirectories and files in the current directory regardless of their write permissions.

[status, message, messageid] = rmdir('dirname','s') removes the directory dirname and its contents from the current directory, returning the status, a message, and the MATLAB® error message ID (see error and lasterror). Here, status is 1 for success and is 0 for error, and message, messageid, and the s input argument are optional.

Remarks

When attempting to remove multiple directories, either by including a wildcard in the directory name or by specifying the 's' flag in the rmdir command, MATLAB throws an error if it is unable remove all directories to which the command applies. The error message contains a listing of those directories and files that MATLAB could not remove.

Examples

Remove Empty Directory

To remove myfiles from the current directory, where myfiles is empty, type

rmdir('myfiles')

If the current directory is matlabr13/work, and myfiles is in d:/matlabr13/work/project/, use the relative path to myfiles

rmdir('project/myfiles')

or the full path to myfiles

rmdir('d:/matlabr13/work/project/myfiles')

Remove Directory and All Contents

To remove myfiles, its subdirectories, and all files in the directories, assuming myfiles is in the current directory, type

rmdir('myfiles','s')

Remove Directory and Return Results

To remove myfiles from the current directory, type

[stat, mess, id]=rmdir('myfiles')

MATLAB returns

stat =
     0

mess =

The directory is not empty.

id =

MATLAB:RMDIR:OSError

indicating the directory myfiles is not empty.

To remove myfiles and its contents, run

[stat, mess]=rmdir('myfiles','s')

and MATLAB returns

stat =
     1

mess =

     ''

indicating myfiles and its contents were removed.

See Also

cd, copyfile, delete, dir, error, fileattrib, filebrowser, lasterror, mkdir, movefile

  


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