Debian Codegraph @

upstream/mageia-cauldron/man3pm/File::Spec.3pm

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man v6.0.2 (Pod::Simple 3.45)
3 .\"
4 .\" Standard preamble:
5 .\" ========================================================================
6 .de Sp \" Vertical space (when we can't use .PP)
7 .if t .sp .5v
8 .if n .sp
9 ..
10 .de Vb \" Begin verbatim text
11 .ft CW
12 .nf
13 .ne \\$1
14 ..
15 .de Ve \" End verbatim text
16 .ft R
17 .fi
18 ..
19 .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
20 .ie n \{\
21 . ds C` ""
22 . ds C' ""
23 'br\}
24 .el\{\
25 . ds C`
26 . ds C'
27 'br\}
28 .\"
29 .\" Escape single quotes in literal strings from groff's Unicode transform.
30 .ie \n(.g .ds Aq \(aq
31 .el .ds Aq '
32 .\"
33 .\" If the F register is >0, we'll generate index entries on stderr for
34 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
35 .\" entries marked with X<> in POD. Of course, you'll have to process the
36 .\" output yourself in some meaningful fashion.
37 .\"
38 .\" Avoid warning from groff about undefined register 'F'.
39 .de IX
40 ..
41 .nr rF 0
42 .if \n(.g .if rF .nr rF 1
43 .if (\n(rF:(\n(.g==0)) \{\
44 . if \nF \{\
45 . de IX
46 . tm Index:\\$1\t\\n%\t"\\$2"
47 ..
48 . if !\nF==2 \{\
49 . nr % 0
50 . nr F 2
51 . \}
52 . \}
53 .\}
54 .rr rF
55 .\"
56 .\" Required to disable full justification in groff 1.23.0.
57 .if n .ds AD l
58 .\" ========================================================================
59 .\"
60 .IX Title "File::Spec 3pm"
61 .TH File::Spec 3pm 2025-06-24 "perl v5.42.0" "Perl Programmers Reference Guide"
62 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
63 .\" way too many mistakes in technical documents.
64 .if n .ad l
65 .nh
66 .SH NAME
67 File::Spec \- portably perform operations on file names
68 .SH SYNOPSIS
69 .IX Header "SYNOPSIS"
70 .Vb 1
71 \& use File::Spec;
72 \&
73 \& my $x = File::Spec\->catfile(\*(Aqa\*(Aq, \*(Aqb\*(Aq, \*(Aqc\*(Aq);
74 .Ve
75 .PP
76 which returns \*(Aqa/b/c\*(Aq under Unix. Or:
77 .PP
78 .Vb 1
79 \& use File::Spec::Functions;
80 \&
81 \& my $x = catfile(\*(Aqa\*(Aq, \*(Aqb\*(Aq, \*(Aqc\*(Aq);
82 .Ve
83 .SH DESCRIPTION
84 .IX Header "DESCRIPTION"
85 This module is designed to support operations commonly performed on file
86 specifications (usually called "file names", but not to be confused with the
87 contents of a file, or Perl\*(Aqs file handles), such as concatenating several
88 directory and file names into a single path, or determining whether a path
89 is rooted. It is based on code directly taken from MakeMaker 5.17, code
90 written by Andreas König, Andy Dougherty, Charles Bailey, Ilya
91 Zakharevich, Paul Schinder, and others.
92 .PP
93 Since these functions are different for most operating systems, each set of
94 OS specific routines is available in a separate module, including:
95 .PP
96 .Vb 5
97 \& File::Spec::Unix
98 \& File::Spec::Mac
99 \& File::Spec::OS2
100 \& File::Spec::Win32
101 \& File::Spec::VMS
102 .Ve
103 .PP
104 The module appropriate for the current OS is automatically loaded by
105 File::Spec. Since some modules (like VMS) make use of facilities available
106 only under that OS, it may not be possible to load all modules under all
107 operating systems.
108 .PP
109 Since File::Spec is object oriented, subroutines should not be called directly,
110 as in:
111 .PP
112 .Vb 1
113 \& File::Spec::catfile(\*(Aqa\*(Aq,\*(Aqb\*(Aq);
114 .Ve
115 .PP
116 but rather as class methods:
117 .PP
118 .Vb 1
119 \& File::Spec\->catfile(\*(Aqa\*(Aq,\*(Aqb\*(Aq);
120 .Ve
121 .PP
122 For simple uses, File::Spec::Functions provides convenient functional
123 forms of these methods.
124 .SH METHODS
125 .IX Header "METHODS"
126 .IP canonpath 2
127 .IX Xref "canonpath"
128 .IX Item "canonpath"
129 No physical check on the filesystem, but a logical cleanup of a
130 path.
131 .Sp
132 .Vb 1
133 \& $cpath = File::Spec\->canonpath( $path ) ;
134 .Ve
135 .Sp
136 Note that this does *not* collapse \fIx/../y\fR sections into \fIy\fR. This
137 is by design. If \fI/foo\fR on your system is a symlink to \fI/bar/baz\fR,
138 then \fI/foo/../quux\fR is actually \fI/bar/quux\fR, not \fI/quux\fR as a naive
139 \&\fI../\fR\-removal would give you. If you want to do this kind of
140 processing, you probably want \f(CW\*(C`Cwd\*(C'\fR\*(Aqs \f(CWrealpath()\fR function to
141 actually traverse the filesystem cleaning up paths like this.
142 .IP catdir 2
143 .IX Xref "catdir"
144 .IX Item "catdir"
145 Concatenate two or more directory names to form a complete path ending
146 with a directory. But remove the trailing slash from the resulting
147 string, because it doesn\*(Aqt look good, isn\*(Aqt necessary and confuses
148 OS/2. Of course, if this is the root directory, don\*(Aqt cut off the
149 trailing slash :\-)
150 .Sp
151 .Vb 1
152 \& $path = File::Spec\->catdir( @directories );
153 .Ve
154 .IP catfile 2
155 .IX Xref "catfile"
156 .IX Item "catfile"
157 Concatenate one or more directory names and a filename to form a
158 complete path ending with a filename
159 .Sp
160 .Vb 1
161 \& $path = File::Spec\->catfile( @directories, $filename );
162 .Ve
163 .IP curdir 2
164 .IX Xref "curdir"
165 .IX Item "curdir"
166 Returns a string representation of the current directory.
167 .Sp
168 .Vb 1
169 \& $curdir = File::Spec\->curdir();
170 .Ve
171 .IP devnull 2
172 .IX Xref "devnull"
173 .IX Item "devnull"
174 Returns a string representation of the null device.
175 .Sp
176 .Vb 1
177 \& $devnull = File::Spec\->devnull();
178 .Ve
179 .IP rootdir 2
180 .IX Xref "rootdir"
181 .IX Item "rootdir"
182 Returns a string representation of the root directory.
183 .Sp
184 .Vb 1
185 \& $rootdir = File::Spec\->rootdir();
186 .Ve
187 .IP tmpdir 2
188 .IX Xref "tmpdir"
189 .IX Item "tmpdir"
190 Returns a string representation of the first writable directory from a
191 list of possible temporary directories. Returns the current directory
192 if no writable temporary directories are found. The list of directories
193 checked depends on the platform; e.g. File::Spec::Unix checks \f(CW$ENV{TMPDIR}\fR
194 (unless taint is on) and \fI/tmp\fR.
195 .Sp
196 .Vb 1
197 \& $tmpdir = File::Spec\->tmpdir();
198 .Ve
199 .IP updir 2
200 .IX Xref "updir"
201 .IX Item "updir"
202 Returns a string representation of the parent directory.
203 .Sp
204 .Vb 1
205 \& $updir = File::Spec\->updir();
206 .Ve
207 .IP no_upwards 2
208 .IX Item "no_upwards"
209 Given a list of files in a directory (such as from \f(CWreaddir()\fR),
210 strip out \f(CW\*(Aq.\*(Aq\fR and \f(CW\*(Aq..\*(Aq\fR.
211 .Sp
212 \&\fBSECURITY NOTE:\fR This does NOT filter paths containing \f(CW\*(Aq..\*(Aq\fR, like
213 \&\f(CW\*(Aq../../../../etc/passwd\*(Aq\fR, only literal matches to \f(CW\*(Aq.\*(Aq\fR and \f(CW\*(Aq..\*(Aq\fR.
214 .Sp
215 .Vb 1
216 \& @paths = File::Spec\->no_upwards( readdir $dirhandle );
217 .Ve
218 .IP case_tolerant 2
219 .IX Item "case_tolerant"
220 Returns a true or false value indicating, respectively, that alphabetic
221 case is not or is significant when comparing file specifications.
222 Cygwin and Win32 accept an optional drive argument.
223 .Sp
224 .Vb 1
225 \& $is_case_tolerant = File::Spec\->case_tolerant();
226 .Ve
227 .IP file_name_is_absolute 2
228 .IX Item "file_name_is_absolute"
229 Takes as its argument a path, and returns true if it is an absolute path.
230 .Sp
231 .Vb 1
232 \& $is_absolute = File::Spec\->file_name_is_absolute( $path );
233 .Ve
234 .Sp
235 This does not consult the local filesystem on Unix, Win32, OS/2, or
236 Mac OS (Classic). It does consult the working environment for VMS
237 (see "file_name_is_absolute" in File::Spec::VMS).
238 .IP path 2
239 .IX Xref "path"
240 .IX Item "path"
241 Takes no argument. Returns the environment variable \f(CW\*(C`PATH\*(C'\fR (or the local
242 platform\*(Aqs equivalent) as a list.
243 .Sp
244 .Vb 1
245 \& @PATH = File::Spec\->path();
246 .Ve
247 .IP join 2
248 .IX Xref "join, path"
249 .IX Item "join"
250 join is the same as catfile.
251 .IP splitpath 2
252 .IX Xref "splitpath split, path"
253 .IX Item "splitpath"
254 Splits a path in to volume, directory, and filename portions. On systems
255 with no concept of volume, returns \*(Aq\*(Aq for volume.
256 .Sp
257 .Vb 4
258 \& ($volume,$directories,$file) =
259 \& File::Spec\->splitpath( $path );
260 \& ($volume,$directories,$file) =
261 \& File::Spec\->splitpath( $path, $no_file );
262 .Ve
263 .Sp
264 For systems with no syntax differentiating filenames from directories,
265 assumes that the last file is a path unless \f(CW$no_file\fR is true or a
266 trailing separator or \fI/.\fR or \fI/..\fR is present. On Unix, this means that \f(CW$no_file\fR
267 true makes this return ( \*(Aq\*(Aq, \f(CW$path\fR, \*(Aq\*(Aq ).
268 .Sp
269 The directory portion may or may not be returned with a trailing \*(Aq/\*(Aq.
270 .Sp
271 The results can be passed to "\fBcatpath()\fR" to get back a path equivalent to
272 (usually identical to) the original path.
273 .IP splitdir 2
274 .IX Xref "splitdir split, dir"
275 .IX Item "splitdir"
276 The opposite of "catdir".
277 .Sp
278 .Vb 1
279 \& @dirs = File::Spec\->splitdir( $directories );
280 .Ve
281 .Sp
282 \&\f(CW$directories\fR must be only the directory portion of the path on systems
283 that have the concept of a volume or that have path syntax that differentiates
284 files from directories.
285 .Sp
286 Unlike just splitting the directories on the separator, empty
287 directory names (\f(CW\*(Aq\*(Aq\fR) can be returned, because these are significant
288 on some OSes.
289 .IP \fBcatpath()\fR 2
290 .IX Item "catpath()"
291 Takes volume, directory and file portions and returns an entire path. Under
292 Unix, \f(CW$volume\fR is ignored, and directory and file are concatenated. A \*(Aq/\*(Aq is
293 inserted if need be. On other OSes, \f(CW$volume\fR is significant.
294 .Sp
295 .Vb 1
296 \& $full_path = File::Spec\->catpath( $volume, $directory, $file );
297 .Ve
298 .IP abs2rel 2
299 .IX Xref "abs2rel absolute, path relative, path"
300 .IX Item "abs2rel"
301 Takes a destination path and an optional base path returns a relative path
302 from the base path to the destination path:
303 .Sp
304 .Vb 2
305 \& $rel_path = File::Spec\->abs2rel( $path ) ;
306 \& $rel_path = File::Spec\->abs2rel( $path, $base ) ;
307 .Ve
308 .Sp
309 If \f(CW$base\fR is not present or \*(Aq\*(Aq, then \fBCwd::cwd()\fR is used. If \f(CW$base\fR is
310 relative, then it is converted to absolute form using
311 "\fBrel2abs()\fR". This means that it is taken to be relative to
312 \&\fBCwd::cwd()\fR.
313 .Sp
314 On systems with the concept of volume, if \f(CW$path\fR and \f(CW$base\fR appear to be
315 on two different volumes, we will not attempt to resolve the two
316 paths, and we will instead simply return \f(CW$path\fR. Note that previous
317 versions of this module ignored the volume of \f(CW$base\fR, which resulted in
318 garbage results part of the time.
319 .Sp
320 On systems that have a grammar that indicates filenames, this ignores the
321 \&\f(CW$base\fR filename as well. Otherwise all path components are assumed to be
322 directories.
323 .Sp
324 If \f(CW$path\fR is relative, it is converted to absolute form using "\fBrel2abs()\fR".
325 This means that it is taken to be relative to \fBCwd::cwd()\fR.
326 .Sp
327 No checks against the filesystem are made. On VMS, there is
328 interaction with the working environment, as logicals and
329 macros are expanded.
330 .Sp
331 Based on code written by Shigio Yamaguchi.
332 .IP \fBrel2abs()\fR 2
333 .IX Xref "rel2abs absolute, path relative, path"
334 .IX Item "rel2abs()"
335 Converts a relative path to an absolute path.
336 .Sp
337 .Vb 2
338 \& $abs_path = File::Spec\->rel2abs( $path ) ;
339 \& $abs_path = File::Spec\->rel2abs( $path, $base ) ;
340 .Ve
341 .Sp
342 If \f(CW$base\fR is not present or \*(Aq\*(Aq, then \fBCwd::cwd()\fR is used. If \f(CW$base\fR is relative,
343 then it is converted to absolute form using "\fBrel2abs()\fR". This means that it
344 is taken to be relative to \fBCwd::cwd()\fR.
345 .Sp
346 On systems with the concept of volume, if \f(CW$path\fR and \f(CW$base\fR appear to be
347 on two different volumes, we will not attempt to resolve the two
348 paths, and we will instead simply return \f(CW$path\fR. Note that previous
349 versions of this module ignored the volume of \f(CW$base\fR, which resulted in
350 garbage results part of the time.
351 .Sp
352 On systems that have a grammar that indicates filenames, this ignores the
353 \&\f(CW$base\fR filename as well. Otherwise all path components are assumed to be
354 directories.
355 .Sp
356 If \f(CW$path\fR is absolute, it is cleaned up and returned using "canonpath".
357 .Sp
358 No checks against the filesystem are made. On VMS, there is
359 interaction with the working environment, as logicals and
360 macros are expanded.
361 .Sp
362 Based on code written by Shigio Yamaguchi.
363 .PP
364 For further information, please see File::Spec::Unix,
365 File::Spec::Mac, File::Spec::OS2, File::Spec::Win32, or
366 File::Spec::VMS.
367 .SH "SEE ALSO"
368 .IX Header "SEE ALSO"
369 File::Spec::Unix, File::Spec::Mac, File::Spec::OS2,
370 File::Spec::Win32, File::Spec::VMS, File::Spec::Functions,
371 ExtUtils::MakeMaker
372 .SH AUTHOR
373 .IX Header "AUTHOR"
374 Maintained by perl5\-porters <\fIperl5\[email protected]\fR>.
375 .PP
376 The vast majority of the code was written by
377 Kenneth Albanowski \f(CW\*(C`<[email protected]>\*(C'\fR,
378 Andy Dougherty \f(CW\*(C`<[email protected]>\*(C'\fR,
379 Andreas König \f(CW\*(C`<[email protected]\-Berlin.DE>\*(C'\fR,
380 Tim Bunce \f(CW\*(C`<[email protected]>\*(C'\fR.
381 VMS support by Charles Bailey \f(CW\*(C`<[email protected]>\*(C'\fR.
382 OS/2 support by Ilya Zakharevich \f(CW\*(C`<[email protected]\-state.edu>\*(C'\fR.
383 Mac support by Paul Schinder \f(CW\*(C`<[email protected]>\*(C'\fR, and
384 Thomas Wegner \f(CW\*(C`<[email protected]>\*(C'\fR.
385 \&\fBabs2rel()\fR and \fBrel2abs()\fR written by Shigio Yamaguchi \f(CW\*(C`<[email protected]>\*(C'\fR,
386 modified by Barrie Slaymaker \f(CW\*(C`<[email protected]>\*(C'\fR.
387 \&\fBsplitpath()\fR, \fBsplitdir()\fR, \fBcatpath()\fR and \fBcatdir()\fR by Barrie Slaymaker.
388 .SH COPYRIGHT
389 .IX Header "COPYRIGHT"
390 Copyright (c) 2004\-2013 by the Perl 5 Porters. All rights reserved.
391 .PP
392 This program is free software; you can redistribute it and/or modify
393 it under the same terms as Perl itself.