MATLAB: Removing an empty folder and subfolder

dirrmdirsystem

I have a code that searches through multiple subfolders and deletes all files with a .EIA extension. I want to know if there is any way I can search through the same subfolders and remove the ones that no longer have any files in them.

Best Answer

The dir structure on those subdirectories will return only the two directories entries '.' and '..'. So, check length(d)==2 and the two d.name match the above is certain; I don't think there's a way two get two entries only and they not be anything but the above so just the length check would be all needed.
Of course, if there's anything otherwise left then the rmdir command will fail so the even simpler way is to just issue it in a try...catch block and those that are empty will disappear almost automagically! :)