rmdir -p on Unices will work that way. If you say rmdir -p foo/bar/baz, it will remove foo/bar/baz, then foo/bar, and finally foo. However, it only works if these directories are all empty (since anything else wouldn’t make sense).
I suppose this is about equivalent, except it also does an rm -r on the top of the path, so if you give it foo/bar/baz it will remove foo/bar/baz and will then remove foo/bar and foo as well if they turn out empty.
use File::Path; use File::Spec::Functions qw( splitdir catdir ); sub rmtree_path { my ( $path ) = @_; rmtree $path; my @path = splitdir $path; do { pop @path } while @path and rmdir catdir @path; }
Untested.
Makeshifts last the longest.
In reply to Re^2: File::Path::rmtree: What am I not grokking?
by Aristotle
in thread File::Path::rmtree: What am I not grokking?
by jkeenan1
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |