cleardir

Version 2.0.0 (1.56 KB) by Ajay Kumar
Delete only the contents of a folder
26 Downloads
Updated 8 Dec 2023

View License

Since delete command doesn't work on folders and rmdir deletes everything including the root folder, I have written this piece of code to remove/delete all the files and subfolders within a given folder without deleting the folder itself. Please specify the full path of the folder in order to empty it's contents.

Cite As

Ajay Kumar (2026). cleardir (https://www.mathworks.com/matlabcentral/fileexchange/155507-cleardir), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2023b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Version Published Release Notes
2.0.0

- Bug fixes (latent bugs highlighted in Stephen23 review)
- Minor code improvements (suggestions from Stephen23's review)
- Up to date comments
Shout out to Stephen23 for his detailed helpful review!

1.0.0