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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |