folderName from the current folder.
be empty. If the operation is not successful, MATLAB® throws an
error to the Command Window.
specified folder and returns a status of
status = rmdir(___)
1 if the operation
is successful. Otherwise,
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.
Remove Folders from Current Folder
Create the folders
myproject/myfiles in the current folder, and then remove them.
mkdir myproject mkdir myproject/myfiles rmdir myproject/myfiles rmdir myproject
Remove Nonempty Folder
Remove the folder
myfiles, which contains the files
Create the folder
myfiles and move the files
myfile2.m from the current folder into the new folder.
mkdir myfiles movefile myfile1.m myfiles movefile myfile2.m myfiles
Try to remove the folder
rmdir. Because the
myfiles folder is not empty, the operation fails and returns 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'
Now, use the 's' flag to remove the folder
myfiles. A status of 1 and an empty
messageid indicate that the operation is successful.
[status, message, messageid] = rmdir('myfiles', 's')
status = logical 1
message = 0x0 empty char array messageid = 0x0 empty char array
folderName — Folder name
character vector | string scalar
Folder name to remove, specified as a character vector or string scalar.
folderName as an absolute or relative
status — Folder removal status
0 | 1
Status of folder indicating if the attempt to remove the folder is
successful, specified as
the attempt is successful,
status is 1. Otherwise,
status is 0.
msg — Error message
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,
msgID — Error message identifier
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,
You can use
rmdirto create folders in remote locations. To write to a remote location,
parentNamemust contain the full path of the file specified as a uniform resource locator (URL) of the form:
It is also valid to use one or three "slash" (
/) characters between
path_to_file. For example:
Based on your remote location,
schema_namecan be one of the values in this table.
Windows Azure® Blob Storage
As with local folders,
rmdircannot remove nonempty virtual folders unless you specify the
sflag. Some file services do not support empty folders. On these services, if
rmdirremoves folders and leaves their parent folder empty, then the parent folder will be removed as well. For more information, see Work with Remote Data.
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 Current Folder Browser command.
Version HistoryIntroduced before R2006a
R2020a: Wildcard expression
*.* on UNIX platforms matches only files that have an extension
Starting in R2020a, on UNIX® platforms, the wildcard expression
*.* no longer
matches folders or files without an extension. In previous releases, the expression
matches folders or files regardless of extension, including files without an
extension. This change of behavior does not apply to Microsoft®