in reply to File::Path::rmtree: What am I not grokking?

Here's a (slightly tested) solution:

use File::Spec (); sub unmkpath { my ($path) = @_; my ($vol, $dirs) = File::Spec->splitpath($path, 1); my @dirs = File::Spec->splitdir($dirs); while (@dirs) { my $dir = File::Spec->catpath($vol, File::Spec->catdir(@dirs), ' +'); rmdir($dir); pop(@dirs); } }

Portable.
Handles pathes with volumes.
Handles absolute paths.
Handles relative paths.

It could be optimized a little.

Replies are listed 'Best First'.
Re^2: File::Path::rmtree: What am I not grokking?
by Aristotle (Chancellor) on Nov 02, 2005 at 22:51 UTC

    Nicely thorough. Along the lines of my other reply,

    use File::Spec::Functions qw( splitpath splitdir catpath catdir ); sub unmkpath { my ( $path ) = @_; my ( $vol, @dir ) = do { my ( $vol, $dirs ) = splitpath( $path, 1 ); ( $vol, splitdir $dirs ); }; pop @dir while @dir and rmdir catpath $vol, catdir( @dir ), ''; }

    Update: fixed a couple typos and a minor forgeto.

    Makeshifts last the longest.