Quantcast

Documentation Center

  • Trial Software
  • Product Updates

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

String specifying the absolute or relative path name of the folder you want to remove.

Default: None

's'

Literal string 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

String containing the warning or error message text if the operation is unsuccessful. An empty string, if the operation is successful.

messageid

String containing the warning or error message ID, if the operation is unsuccessful. MATLAB returns an empty string if the operation is successful.

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

expand 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.

See Also

| | | | | | |

Was this topic helpful?