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
7 modules
8
10 require File::Spec::Unix; # Done automatically by File::Spec
11
13 Methods for manipulating file specifications. Other File::Spec
14 modules, such as File::Spec::Mac, inherit from File::Spec::Unix and
15 override 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
28 probably 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
33 ending with a directory. But remove the trailing slash from the
34 resulting string, because it doesn't look good, isn't necessary and
35 confuses 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
40 complete 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
71 equivalents.)
72
73 case_tolerant
74 Returns a true or false value indicating, respectively, that
75 alphabetic is not or is significant when comparing file
76 specifications.
77
78 file_name_is_absolute
79 Takes as argument a path and returns true if it is an absolute path.
80
81 This does not consult the local filesystem on Unix, Win32, OS/2 or
82 Mac OS (Classic). It does consult the working environment for VMS
83 (see "file_name_is_absolute" in File::Spec::VMS).
84
85 path
86 Takes no argument, returns the environment variable PATH as an array.
87
88 join
89 join is the same as catfile.
90
91 splitpath
92 ($volume,$directories,$file) = File::Spec->splitpath( $path );
93 ($volume,$directories,$file) = File::Spec->splitpath( $path, $no_file );
94
95 Splits a path into volume, directory, and filename portions. On
96 systems with no concept of volume, returns '' for volume.
97
98 For systems with no syntax differentiating filenames from
99 directories, assumes that the last file is a path unless $no_file is
100 true or a trailing separator or /. or /.. is present. On Unix this
101 means that $no_file true makes this return ( '', $path, '' ).
102
103 The directory portion may or may not be returned with a trailing '/'.
104
105 The results can be passed to "catpath()" to get back a path
106 equivalent to (usually identical to) the original path.
107
108 splitdir
109 The opposite of "catdir()".
110
111 @dirs = File::Spec->splitdir( $directories );
112
113 $directories must be only the directory portion of the path on
114 systems that have the concept of a volume or that have path syntax
115 that differentiates files from directories.
116
117 Unlike just splitting the directories on the separator, empty
118 directory names ('') can be returned, because these are significant
119 on some OSs.
120
121 On Unix,
122
123 File::Spec->splitdir( "/a/b//c/" );
124
125 Yields:
126
127 ( '', 'a', 'b', '', 'c', '' )
128
129 catpath()
130 Takes volume, directory and file portions and returns an entire path.
131 Under Unix, $volume is ignored, and directory and file are
132 concatenated. A '/' is inserted if needed (though if the directory
133 portion doesn't start with '/' it is not added). On other OSs,
134 $volume is significant.
135
136 abs2rel
137 Takes a destination path and an optional base path returns a relative
138 path from the base path to the destination path:
139
140 $rel_path = File::Spec->abs2rel( $path ) ;
141 $rel_path = File::Spec->abs2rel( $path, $base ) ;
142
143 If $base is not present or '', then cwd() is used. If $base is
144 relative, then it is converted to absolute form using "rel2abs()".
145 This means that it is taken to be relative to cwd().
146
147 On systems that have a grammar that indicates filenames, this ignores
148 the $base filename. Otherwise all path components are assumed to be
149 directories.
150
151 If $path is relative, it is converted to absolute form using
152 "rel2abs()". This means that it is taken to be relative to cwd().
153
154 No checks against the filesystem are made. On VMS, there is
155 interaction with the working environment, as logicals and macros are
156 expanded.
157
158 Based on code written by Shigio Yamaguchi.
159
160 rel2abs()
161 Converts a relative path to an absolute path.
162
163 $abs_path = File::Spec->rel2abs( $path ) ;
164 $abs_path = File::Spec->rel2abs( $path, $base ) ;
165
166 If $base is not present or '', then cwd() is used. If $base is
167 relative, then it is converted to absolute form using "rel2abs()".
168 This means that it is taken to be relative to cwd().
169
170 On systems that have a grammar that indicates filenames, this ignores
171 the $base filename. Otherwise all path components are assumed to be
172 directories.
173
174 If $path is absolute, it is cleaned up and returned using
175 "canonpath()".
176
177 No checks against the filesystem are made. On VMS, there is
178 interaction with the working environment, as logicals and macros are
179 expanded.
180
181 Based on code written by Shigio Yamaguchi.
182
184 Copyright (c) 2004 by the Perl 5 Porters. All rights reserved.
185
186 This program is free software; you can redistribute it and/or modify it
187 under the same terms as Perl itself.
188
190 File::Spec
191
192
193
194perl v5.10.1 2009-05-10 File::Spec::Unix(3pm)