Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

rmdir

Remove folder

Syntax

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

Description

rmdir(folderName) removes the folder folderName from the current folder if folderName is empty. If folderName is not in the current folder, then specify the relative path or the full path for folderName.

rmdir(folderName,'s') removes the folder folderName and its contents from the current folder. With the 's' option, rmdir attempts to remove all subfolders and files in folderName regardless of their write permissions.

[status, message, messageid] = rmdir(folderName,'s') removes the folder folderName and its contents from the current folder, returning the status, a message, and the MATLAB® message ID.

Input Arguments

folderName

Absolute or relative path name of the folder you want to remove, specified as a character vector.

Default: None

's'

Literal that directs rmdir to remove all subfolders and files in the specified folder, regardless of their write permissions. The result for read-only files follows the practices of the operating system.

Default: rmdir does not remove subfolders and files in the specified folder.

Output Arguments

status

Logical scalar indicating the outcome of the rmdir operation. The status value is 1 if the operation was successful and 0 if it returned an error.

message

Warning or error message text of an unsuccessful operation, specified as a character vector. If the operation is successful, message is empty.

messageid

Warning or error message ID of an unsuccessful operation, specified as a character vector. If the operation is successful, messageid is empty.

Examples

These examples remove an empty folder, myfiles, assuming it is in the current folder:

% Remove myfiles from the current folder:

rmdir('myfiles')

% Use the relative path to remove myfiles. Assuming 
% the current folder is matlab/work and myfiles is in 
% d:/matlab/work/project, type this:

rmdir('project/myfiles')

% Use the full path to remove myfiles, assuming 
% the current folder is matlab/work and myfiles is in 
% d:/matlab/work/project:

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

This example removes the myfiles folder and its contents, assuming myfiles is in the current folder:

rmdir('myfiles','s')

This example unsuccessfully attempts to remove the myfiles folder and its contents. It directs MATLAB to display the results.

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

MATLAB returns:

stat =
     0

mess =

No directories were removed.

id =

MATLAB:RMDIR:NoDirectoriesRemoved

This example successfully removes the myfiles folder and its contents. It directs MATLAB to display the results.

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

MATLAB returns:

stat =
     1

mess =

     ''

Alternatives

Open the Current Folder browser by running filebrowser. Then, in the Current Folder browser, right-click the folder name and select Delete from the context menu.

More About

collapse all

Tips

  • If you specify the 's' flag or include a wildcard in the folder name, MATLAB produces an error if it is unable to remove all folders. The error message lists the folder and files that MATLAB could not remove.

Introduced before R2006a

Was this topic helpful?