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

Syntax

rmdir folderName
rmdir folderName s
status = rmdir(___)
[status,msg] = rmdir(___)
[status,msg,msgID] = rmdir(___)

Description

example

rmdir folderName removes the folder folderName from the current folder. folderName must be empty. If the operation is not successful, MATLAB® throws an error to the Command Window.

example

rmdir folderName s attempts to remove the folder folderName and all subfolders and files in folderName, regardless of their write permissions. The result for read-only files follows the practices of the operating system.

example

status = rmdir(___) removes the specified folder and returns a status of 1 if the operation is successful. Otherwise, it returns 0. Warnings and errors are not thrown to the Command Window. You can use this syntax with any of the input argument combinations in the previous syntaxes.

example

[status,msg] = rmdir(___) also returns the message text for any warning or error that occurs. You can use this syntax with any of the input argument combinations in the previous syntaxes.

example

[status,msg,msgID] = rmdir(___) also returns the message ID for any warning or error that occurs. You can use this syntax with any of the input argument combinations in the previous syntaxes.

Examples

collapse all

Create and then remove the folders myproject and myproject/myfiles from the current folder.

mkdir myproject
mkdir myproject/myfiles

rmdir myproject/myfiles
rmdir myproject

Remove the folder myfiles, which contains the files myfile1.m and myfile2.m.

Create the folder myfiles and move the files myfile1.m and myfile2.m into the folder.

mkdir myfiles
movefile myfile1.m myfiles
movefile myfile2.m myfiles

Remove the folder myfiles. The operation fails because myfiles is not empty, returning a status of 0 and an error message detailing why the operation failed.

[status, message, messageid] = rmdir('myfiles')
status =

  logical

   0


message =

    'No directories were removed.'


messageid =

    'MATLAB:RMDIR:NoDirectoriesRemoved'

Remove the folder myfiles using the 's' flag. A status of 1 and an empty message and messageid indicate that the operation is successful.

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

  logical

   1


message =

  0×0 empty char array


messageid =

  0×0 empty char array

Input Arguments

collapse all

Name of the folder to remove, specified as a character vector. folderName can be specified as an absolute or relative path.

Output Arguments

collapse all

Indication of whether the attempt to remove the folder is successful, specified as 0 or 1. If the attempt is successful, status is 1. Otherwise, status is 0.

Data Types: logical

Error message, specified as a character vector. If an error or warning occurs, msg contains the message text of the error or warning. Otherwise, msg is empty, ''.

Error message identifier, specified as a character vector. If an error or warning occurs, msgID contains the message identifier of the error or warning. Otherwise, msgID is empty, ''.

Alternative Functionality

In the Current Folder browser, right-click the folder name and select Delete from the context menu. To open the Current Folder browser, use the filebrowser command.

See Also

| | | | |

Introduced before R2006a

Was this topic helpful?