Skip to content

Commit

Permalink
Add recursive rmdir example per issue #852
Browse files Browse the repository at this point in the history
  • Loading branch information
Brock Wilcox committed Oct 23, 2016
1 parent 763a3a5 commit 8de94c9
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions doc/Type/IO/Path.pod6
Expand Up @@ -294,6 +294,20 @@ Returns C<True> on success. Throws an exception of type
L<X::IO::Rmdir> if the directory cannot be removed (e.g.
the directory is not empty, or the path is not a directory).
Since this only works on an empty directory, to removIhe a directory and its
contents you will have to do something more complex.
# When we have a directory first recurse, then remove it
multi sub rm-all(IO::Path $path where :d) {
$path.dir.map({ rm-all($^p) });
rmdir($path)
}
# Otherwise just remove the thing directly
multi sub rm-all(IO::Path $path) { $path.unlink }
See also L<rmtree in File::Directory::Tree|https://github.com/labster/p6-file-directory-tree>.
=head2 routine chmod
sub chmod($mode, *@filenames --> List)
Expand Down

0 comments on commit 8de94c9

Please sign in to comment.