use File::Path;
mkpath(['/foo/bar/baz', 'blurfl/quux'], 1, 0711);
rmtree(['/foo/bar/baz', 'blurfl/quux'], 1, 1);
The mkpath()
function provides a convenient way to create directories,
even if
your mkdir(2) won't create more than one level of directory at a
time. mkpath()
takes three arguments:
The name of the path to create, or a reference
to a list of paths to create
A Boolean value, which if true will cause mkpath()
to print the name of each directory as it is created
(defaults to false)
The numeric mode to use when creating the directories
(defaults to 0777
)
It returns a list of all directories created, including intermediate
directories, which are assumed to be delimited by
the UNIX path separator, /
.
Similarly, the rmtree()
function provides a convenient way to delete a
subtree from the directory structure, much like the UNIX rm -r
command. rmtree()
takes three arguments:
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.
A Boolean value, which if true will cause rmtree()
to
print a message each time it examines a file, giving the
name of the file and indicating whether it's using rmdir(2)
or unlink(2) to remove it, or whether it's skipping it.
(This argument defaults to false.)
A Boolean value, which if true will cause rmtree()
to
skip any files to which you do not have delete access
(if running under VMS) or write access (if running
under another operating system). This will change in the future when
a criterion for "delete permission" under operating systems other
than VMS is settled. (This argument defaults to false.)
rmtree()
returns the number of files successfully deleted.
Symbolic links are treated as ordinary files.