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

I don't know of anything that does what you want with a single command.

How about this?

use File::Path; use File::Spec; use Test::More qw|no_plan|; my $tmp = "/Users/jimk/tmp"; chdir $tmp or die; my $partial = "alpha/beta/gamma"; mkpath($partial); ok(-d "$tmp/$partial", "$tmp/$partial created"); rmfromtop($partial); ok(! -d "$tmp/$partial", "$tmp/$partial deleted"); ok(! -d "alpha/beta", "alpha/beta deleted"); ok(! -d "alpha", "alpha deleted"); sub rmfromtop { rmtree((File::Spec->splitdir(+shift))[0]); }

jimk

Replies are listed 'Best First'.
Re^3: File::Path::rmtree: What am I not grokking?
by ikegami (Patriarch) on Nov 02, 2005 at 22:26 UTC
    I think you missed the point. It deletes much more than it should. For example, it will delete alpha/important. Also, it doesn't work with absolute paths.
Re^3: File::Path::rmtree: What am I not grokking?
by Aristotle (Chancellor) on Nov 02, 2005 at 22:31 UTC

    What’s the point? If you rmtree('alpha') it will recurse into all the subdirs anyway.

    Makeshifts last the longest.

      The point was that I didn't want to hardcode alpha. I wanted to supply the same, single variable to rmfromtop as I did to mkpath. And just as mkpath was creating a whole tree, I wanted a function to delete that same whole tree. Since this will be used in a testing context, I'm going to be creating the tree, verifying that I created it, deleting the tree, and verifying that I deleted it.

      jimk

        But you have to splitdirs anyway in order to remove all components, so why not simply rmtree +( splitdirs $partial )[ 0 ]? That has the exact same effect.

        Makeshifts last the longest.