KevinADC....

File::Path removes everything. Not just non-empty directories.

savanm...

While it is the inverted answer, you are running rmdir on EVERY filename, not just directories or even empty directories. Though That is quite valid as it does the required tests.

Now to try and answer for real...

To try and remove directories that are NOT empty, is tricky. A directory with a directory...