1File::Spec::Unix(3pm) Perl Programmers Reference Guide File::Spec::Unix(3pm)
2
3
4
6 File::Spec::Unix - File::Spec for Unix, base for other File::Spec mod‐
7 ules
8
10 require File::Spec::Unix; # Done automatically by File::Spec
11
13 Methods for manipulating file specifications. Other File::Spec mod‐
14 ules, such as File::Spec::Mac, inherit from File::Spec::Unix and over‐
15 ride specific methods.
16
18 canonpath()
19 No physical check on the filesystem, but a logical cleanup of a path.
20 On UNIX eliminates successive slashes and successive "/.".
21
22 $cpath = File::Spec->canonpath( $path ) ;
23
24 Note that this does *not* collapse x/../y sections into y. This is
25 by design. If /foo on your system is a symlink to /bar/baz, then
26 /foo/../quux is actually /bar/quux, not /quux as a naive ../-removal
27 would give you. If you want to do this kind of processing, you prob‐
28 ably want "Cwd"'s "realpath()" function to actually traverse the
29 filesystem cleaning up paths like this.
30
31 catdir()
32 Concatenate two or more directory names to form a complete path end‐
33 ing with a directory. But remove the trailing slash from the result‐
34 ing string, because it doesn't look good, isn't necessary and con‐
35 fuses OS2. Of course, if this is the root directory, don't cut off
36 the trailing slash :-)
37
38 catfile
39 Concatenate one or more directory names and a filename to form a com‐
40 plete path ending with a filename
41
42 curdir
43 Returns a string representation of the current directory. "." on
44 UNIX.
45
46 devnull
47 Returns a string representation of the null device. "/dev/null" on
48 UNIX.
49
50 rootdir
51 Returns a string representation of the root directory. "/" on UNIX.
52
53 tmpdir
54 Returns a string representation of the first writable directory from
55 the following list or the current directory if none from the list are
56 writable:
57
58 $ENV{TMPDIR}
59 /tmp
60
61 Since perl 5.8.0, if running under taint mode, and if $ENV{TMPDIR} is
62 tainted, it is not used.
63
64 updir
65 Returns a string representation of the parent directory. ".." on
66 UNIX.
67
68 no_upwards
69 Given a list of file names, strip out those that refer to a parent
70 directory. (Does not strip symlinks, only '.', '..', and equiva‐
71 lents.)
72
73 case_tolerant
74 Returns a true or false value indicating, respectively, that alpha‐
75 betic is not or is significant when comparing file specifications.
76
77 file_name_is_absolute
78 Takes as argument a path and returns true if it is an absolute path.
79
80 This does not consult the local filesystem on Unix, Win32, OS/2 or
81 Mac OS (Classic). It does consult the working environment for VMS
82 (see "file_name_is_absolute" in File::Spec::VMS).
83
84 path
85 Takes no argument, returns the environment variable PATH as an array.
86
87 join
88 join is the same as catfile.
89
90 splitpath
91 ($volume,$directories,$file) = File::Spec->splitpath( $path );
92 ($volume,$directories,$file) = File::Spec->splitpath( $path, $no_file );
93
94 Splits a path into volume, directory, and filename portions. On sys‐
95 tems with no concept of volume, returns '' for volume.
96
97 For systems with no syntax differentiating filenames from directo‐
98 ries, assumes that the last file is a path unless $no_file is true or
99 a trailing separator or /. or /.. is present. On Unix this means that
100 $no_file true makes this return ( '', $path, '' ).
101
102 The directory portion may or may not be returned with a trailing '/'.
103
104 The results can be passed to "catpath()" to get back a path equiva‐
105 lent to (usually identical to) the original path.
106
107 splitdir
108 The opposite of "catdir()".
109
110 @dirs = File::Spec->splitdir( $directories );
111
112 $directories must be only the directory portion of the path on sys‐
113 tems that have the concept of a volume or that have path syntax that
114 differentiates files from directories.
115
116 Unlike just splitting the directories on the separator, empty direc‐
117 tory names ('') can be returned, because these are significant on
118 some OSs.
119
120 On Unix,
121
122 File::Spec->splitdir( "/a/b//c/" );
123
124 Yields:
125
126 ( '', 'a', 'b', '', 'c', '' )
127
128 catpath()
129 Takes volume, directory and file portions and returns an entire path.
130 Under Unix, $volume is ignored, and directory and file are concate‐
131 nated. A '/' is inserted if needed (though if the directory portion
132 doesn't start with '/' it is not added). On other OSs, $volume is
133 significant.
134
135 abs2rel
136 Takes a destination path and an optional base path returns a relative
137 path from the base path to the destination path:
138
139 $rel_path = File::Spec->abs2rel( $path ) ;
140 $rel_path = File::Spec->abs2rel( $path, $base ) ;
141
142 If $base is not present or '', then cwd() is used. If $base is rela‐
143 tive, then it is converted to absolute form using "rel2abs()". This
144 means that it is taken to be relative to cwd().
145
146 On systems that have a grammar that indicates filenames, this ignores
147 the $base filename. Otherwise all path components are assumed to be
148 directories.
149
150 If $path is relative, it is converted to absolute form using
151 "rel2abs()". This means that it is taken to be relative to cwd().
152
153 No checks against the filesystem are made. On VMS, there is interac‐
154 tion with the working environment, as logicals and macros are
155 expanded.
156
157 Based on code written by Shigio Yamaguchi.
158
159 rel2abs()
160 Converts a relative path to an absolute path.
161
162 $abs_path = File::Spec->rel2abs( $path ) ;
163 $abs_path = File::Spec->rel2abs( $path, $base ) ;
164
165 If $base is not present or '', then cwd() is used. If $base is rela‐
166 tive, then it is converted to absolute form using "rel2abs()". This
167 means that it is taken to be relative to cwd().
168
169 On systems that have a grammar that indicates filenames, this ignores
170 the $base filename. Otherwise all path components are assumed to be
171 directories.
172
173 If $path is absolute, it is cleaned up and returned using "canon‐
174 path()".
175
176 No checks against the filesystem are made. On VMS, there is interac‐
177 tion with the working environment, as logicals and macros are
178 expanded.
179
180 Based on code written by Shigio Yamaguchi.
181
183 Copyright (c) 2004 by the Perl 5 Porters. All rights reserved.
184
185 This program is free software; you can redistribute it and/or modify it
186 under the same terms as Perl itself.
187
189 File::Spec
190
191
192
193perl v5.8.8 2001-09-21 File::Spec::Unix(3pm)