rmdir
Removes a folder.
Category: Programming > Files and Folders
Syntax
rmdir(folder)
Removes an empty folder.
rmdir(folder, 's')
Removes the folder with all its files and subfolders.
[status, message] = rmdir(___)
Returns the outcome instead of raising an error.
Description
Without 's', a folder that still has content cannot be removed. The removal with 's' is permanent unless a recycle bin is in use, so check the folder name first. Without output arguments any failure is an error; with them the call returns false and a message.
Input arguments
folder- Folder to remove.
's'- Option to remove the contents too.
Output arguments
statustrueon success.message- Text describing the failure, empty on success.
Example
Empty-only versus recursive removal
mkdir tmp/inner
writelines('x', 'tmp/inner/f.txt');
[ok, msg] = rmdir('tmp');
ok
rmdir('tmp', 's');
isfolder('tmp')
Output
ok = logical
0
ans = logical
0
Notes
MatLivre's rmdir returns at most two outputs, status and message.