The documentation to File::Path suggests that the rmtree() function rolls back the result of that same module's mkpath() function.

Similarly, the "rmtree" function provides a convenient way to delete a subtree from the directory structure, much like the Unix command "rm -r". "rmtree" takes three arguments:

o the root of the subtree to delete, or a reference to a list of roots. All of the files and directories below each root, as well as the roots themselves, will be deleted.

As I interpret this documentation -- particularly the reference to the "root" of the subtree -- if I create a directory structure alpha/beta/gamma with mkpath, I should expect to find alpha/ and all subdirectories and files beneath it eliminated by using rmtree(). But that's not what I'm getting.

use File::Path; 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"); rmtree($partial); ok(! -d "$tmp/$partial", "$tmp/$partial deleted");

Notwithstanding what ok() is reporting, only the lowest level subdirectory, gamma, is being deleted. But what I really wanted to accomplish was deleting alpha/, alpha/beta/, alpha/beta/gamma/. What am I not getting about rmtree?

And while we're talking about File::Path ... is the / following 'mkpath' and preceding 'foo' an error?

mkpath(['/foo/bar/baz', 'blurfl/quux'], 1, 0711); rmtree(['foo/bar/baz', 'blurfl/quux'], 1, 1);

Shouldn't it simply be ...

mkpath(['foo/bar/baz', 'blurfl/quux'], 1, 0711); rmtree(['foo/bar/baz', 'blurfl/quux'], 1, 1);

Thank you very much.

Jim Keenan


In reply to File::Path::rmtree: What am I not grokking? by jkeenan1

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.