Documentation for sub rmdir

Documentation for sub rmdir, assembled from the following types:

class IO::Path

From IO::Path

(IO::Path) routine rmdir

Defined as:

sub    rmdir(IO $dir --> Bool)
method rmdir(IO::Path:D: --> Bool)

Remove the given directory if it is empty.

Returns True on success. Throws an exception of type 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 remove 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{
    .&rm-all for $path.dir;
    rmdir($path)
}
 
# Otherwise just remove the thing directly 
multi sub rm-all(IO::Path $path{ $path.unlink }

See also rmtree in File::Directory::Tree.