1File::Path(3pm)        Perl Programmers Reference Guide        File::Path(3pm)
2
3
4

NAME

6       File::Path - create or remove directory trees
7

SYNOPSIS

9           use File::Path;
10
11           mkpath(['/foo/bar/baz', 'blurfl/quux'], 1, 0711);
12           rmtree(['foo/bar/baz', 'blurfl/quux'], 1, 1);
13

DESCRIPTION

15       The "mkpath" function provides a convenient way to create directories,
16       even if your "mkdir" kernel call won't create more than one level of
17       directory at a time.  "mkpath" takes three arguments:
18
19       ·   the name of the path to create, or a reference to a list of paths
20           to create,
21
22       ·   a boolean value, which if TRUE will cause "mkpath" to print the
23           name of each directory as it is created (defaults to FALSE), and
24
25       ·   the numeric mode to use when creating the directories (defaults to
26           0777), to be modified by the current umask.
27
28       It returns a list of all directories (including intermediates, deter‐
29       mined using the Unix '/' separator) created.
30
31       If a system error prevents a directory from being created, then the
32       "mkpath" function throws a fatal error with "Carp::croak". This error
33       can be trapped with an "eval" block:
34
35         eval { mkpath($dir) };
36         if ($@) {
37           print "Couldn't create $dir: $@";
38         }
39
40       Similarly, the "rmtree" function provides a convenient way to delete a
41       subtree from the directory structure, much like the Unix command "rm
42       -r".  "rmtree" takes three arguments:
43
44       ·   the root of the subtree to delete, or a reference to a list of
45           roots.  All of the files and directories below each root, as well
46           as the roots themselves, will be deleted.
47
48       ·   a boolean value, which if TRUE will cause "rmtree" to print a mes‐
49           sage each time it examines a file, giving the name of the file, and
50           indicating whether it's using "rmdir" or "unlink" to remove it, or
51           that it's skipping it.  (defaults to FALSE)
52
53       ·   a boolean value, which if TRUE will cause "rmtree" to skip any
54           files to which you do not have delete access (if running under VMS)
55           or write access (if running under another OS).  This will change in
56           the future when a criterion for 'delete permission' under OSs other
57           than VMS is settled.  (defaults to FALSE)
58
59       It returns the number of files successfully deleted.  Symlinks are sim‐
60       ply deleted and not followed.
61
62       NOTE: There are race conditions internal to the implementation of
63       "rmtree" making it unsafe to use on directory trees which may be
64       altered or moved while "rmtree" is running, and in particular on any
65       directory trees with any path components or subdirectories potentially
66       writable by untrusted users.
67
68       Additionally, if the third parameter is not TRUE and "rmtree" is inter‐
69       rupted, it may leave files and directories with permissions altered to
70       allow deletion (and older versions of this module would even set files
71       and directories to world-read/writable!)
72
73       Note also that the occurrence of errors in "rmtree" can be determined
74       only by trapping diagnostic messages using $SIG{__WARN__}; it is not
75       apparent from the return value.
76

DIAGNOSTICS

78       ·   On Windows, if "mkpath" gives you the warning: No such file or
79           directory, this may mean that you've exceeded your filesystem's
80           maximum path length.
81

AUTHORS

83       Tim Bunce <Tim.Bunce@ig.co.uk> and Charles Bailey <bailey@new‐
84       man.upenn.edu>
85
86
87
88perl v5.8.8                       2001-09-21                   File::Path(3pm)
Impressum