2 <!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns=
"http://www.w3.org/1999/xhtml">
5 <title>File::Spec - portably perform operations on file names
</title>
6 <meta http-equiv=
"content-type" content=
"text/html; charset=utf-8" />
7 <link rev=
"made" href=
"mailto:" />
10 <body style=
"background-color: white">
11 <table border=
"0" width=
"100%" cellspacing=
"0" cellpadding=
"3">
12 <tr><td class=
"block" style=
"background-color: #cccccc" valign=
"middle">
13 <big><strong><span class=
"block"> File::Spec - portably perform operations on file names
</span></strong></big>
17 <p><a name=
"__index__"></a></p>
22 <li><a href=
"#name">NAME
</a></li>
23 <li><a href=
"#synopsis">SYNOPSIS
</a></li>
24 <li><a href=
"#description">DESCRIPTION
</a></li>
25 <li><a href=
"#methods">METHODS
</a></li>
26 <li><a href=
"#see_also">SEE ALSO
</a></li>
27 <li><a href=
"#author">AUTHOR
</a></li>
28 <li><a href=
"#copyright">COPYRIGHT
</a></li>
35 <h1><a name=
"name">NAME
</a></h1>
36 <p>File::Spec - portably perform operations on file names
</p>
40 <h1><a name=
"synopsis">SYNOPSIS
</a></h1>
44 $x=File::Spec-
>catfile('a', 'b', 'c');
</pre>
45 <p>which returns 'a/b/c' under Unix. Or:
</p>
47 use File::Spec::Functions;
</pre>
49 $x = catfile('a', 'b', 'c');
</pre>
53 <h1><a name=
"description">DESCRIPTION
</a></h1>
54 <p>This module is designed to support operations commonly performed on file
55 specifications (usually called ``file names'', but not to be confused with the
56 contents of a file, or Perl's file handles), such as concatenating several
57 directory and file names into a single path, or determining whether a path
58 is rooted. It is based on code directly taken from MakeMaker
5.17, code
59 written by Andreas K
önig, Andy Dougherty, Charles Bailey, Ilya
60 Zakharevich, Paul Schinder, and others.
</p>
61 <p>Since these functions are different for most operating systems, each set of
62 OS specific routines is available in a separate module, including:
</p>
69 <p>The module appropriate for the current OS is automatically loaded by
70 File::Spec. Since some modules (like VMS) make use of facilities available
71 only under that OS, it may not be possible to load all modules under all
72 operating systems.
</p>
73 <p>Since File::Spec is object oriented, subroutines should not be called directly,
76 File::Spec::catfile('a','b');
</pre>
77 <p>but rather as class methods:
</p>
79 File::Spec-
>catfile('a','b');
</pre>
80 <p>For simple uses,
<a href=
"file://C|\msysgit\mingw\html/lib/File/Spec/Functions.html">the File::Spec::Functions manpage
</a> provides convenient functional
81 forms of these methods.
</p>
85 <h1><a name=
"methods">METHODS
</a></h1>
87 <dt><strong><a name=
"item_canonpath">canonpath
</a></strong>
90 <p>No physical check on the filesystem, but a logical cleanup of a
95 $cpath = File::Spec-
>canonpath( $path ) ;
</pre>
98 <p>Note that this does *not* collapse
<em>x/../y
</em> sections into
<em>y
</em>. This
99 is by design. If
<em>/foo
</em> on your system is a symlink to
<em>/bar/baz
</em>,
100 then
<em>/foo/../quux
</em> is actually
<em>/bar/quux
</em>, not
<em>/quux
</em> as a naive
101 <em>../
</em>-removal would give you. If you want to do this kind of
102 processing, you probably want
<code>Cwd
</code>'s
<code>realpath()
</code> function to
103 actually traverse the filesystem cleaning up paths like this.
</p>
106 <dt><strong><a name=
"item_catdir">catdir
</a></strong>
109 <p>Concatenate two or more directory names to form a complete path ending
110 with a directory. But remove the trailing slash from the resulting
111 string, because it doesn't look good, isn't necessary and confuses
112 OS/
2. Of course, if this is the root directory, don't cut off the
113 trailing slash :-)
</p>
117 $path = File::Spec-
>catdir( @directories );
</pre>
120 <dt><strong><a name=
"item_catfile">catfile
</a></strong>
123 <p>Concatenate one or more directory names and a filename to form a
124 complete path ending with a filename
</p>
128 $path = File::Spec-
>catfile( @directories, $filename );
</pre>
131 <dt><strong><a name=
"item_curdir">curdir
</a></strong>
134 <p>Returns a string representation of the current directory.
</p>
138 $curdir = File::Spec-
>curdir();
</pre>
141 <dt><strong><a name=
"item_devnull">devnull
</a></strong>
144 <p>Returns a string representation of the null device.
</p>
148 $devnull = File::Spec-
>devnull();
</pre>
151 <dt><strong><a name=
"item_rootdir">rootdir
</a></strong>
154 <p>Returns a string representation of the root directory.
</p>
158 $rootdir = File::Spec-
>rootdir();
</pre>
161 <dt><strong><a name=
"item_tmpdir">tmpdir
</a></strong>
164 <p>Returns a string representation of the first writable directory from a
165 list of possible temporary directories. Returns the current directory
166 if no writable temporary directories are found. The list of directories
167 checked depends on the platform; e.g. File::Spec::Unix checks
<code>$ENV{TMPDIR}
</code>
168 (unless taint is on) and
<em>/tmp
</em>.
</p>
172 $tmpdir = File::Spec-
>tmpdir();
</pre>
175 <dt><strong><a name=
"item_updir">updir
</a></strong>
178 <p>Returns a string representation of the parent directory.
</p>
182 $updir = File::Spec-
>updir();
</pre>
185 <dt><strong><a name=
"item_no_upwards">no_upwards
</a></strong>
188 <p>Given a list of file names, strip out those that refer to a parent
189 directory. (Does not strip symlinks, only '.', '..', and equivalents.)
</p>
193 @paths = File::Spec-
>no_upwards( @paths );
</pre>
196 <dt><strong><a name=
"item_case_tolerant">case_tolerant
</a></strong>
199 <p>Returns a true or false value indicating, respectively, that alphabetic
200 case is not or is significant when comparing file specifications.
</p>
204 $is_case_tolerant = File::Spec-
>case_tolerant();
</pre>
207 <dt><strong><a name=
"item_file_name_is_absolute">file_name_is_absolute
</a></strong>
210 <p>Takes as its argument a path, and returns true if it is an absolute path.
</p>
214 $is_absolute = File::Spec-
>file_name_is_absolute( $path );
</pre>
217 <p>This does not consult the local filesystem on Unix, Win32, OS/
2, or
218 Mac OS (Classic). It does consult the working environment for VMS
219 (see
<a href=
"file://C|\msysgit\mingw\html/lib/File/Spec/VMS.html#file_name_is_absolute">file_name_is_absolute in the File::Spec::VMS manpage
</a>).
</p>
222 <dt><strong><a name=
"item_path">path
</a></strong>
225 <p>Takes no argument. Returns the environment variable
<code>PATH
</code> (or the local
226 platform's equivalent) as a list.
</p>
230 @PATH = File::Spec-
>path();
</pre>
233 <dt><strong><a name=
"item_join">join
</a></strong>
236 <p>join is the same as catfile.
</p>
239 <dt><strong><a name=
"item_splitpath">splitpath
</a></strong>
242 <p>Splits a path in to volume, directory, and filename portions. On systems
243 with no concept of volume, returns '' for volume.
</p>
247 ($volume,$directories,$file) = File::Spec-
>splitpath( $path );
248 ($volume,$directories,$file) = File::Spec-
>splitpath( $path, $no_file );
</pre>
251 <p>For systems with no syntax differentiating filenames from directories,
252 assumes that the last file is a path unless
<code>$no_file
</code> is true or a
253 trailing separator or
<em>/.
</em> or
<em>/..
</em> is present. On Unix, this means that
<code>$no_file
</code>
254 true makes this return ( '', $path, '' ).
</p>
257 <p>The directory portion may or may not be returned with a trailing '/'.
</p>
260 <p>The results can be passed to
<a href=
"#item_catpath">catpath()
</a> to get back a path equivalent to
261 (usually identical to) the original path.
</p>
264 <dt><strong><a name=
"item_splitdir">splitdir
</a></strong>
267 <p>The opposite of
<a href=
"#item_catdir">catdir()
</a>.
</p>
271 @dirs = File::Spec-
>splitdir( $directories );
</pre>
274 <p><code>$directories
</code> must be only the directory portion of the path on systems
275 that have the concept of a volume or that have path syntax that differentiates
276 files from directories.
</p>
279 <p>Unlike just splitting the directories on the separator, empty
280 directory names (
<code>''
</code>) can be returned, because these are significant
284 <dt><strong><a name=
"item_catpath"><code>catpath()
</code></a></strong>
287 <p>Takes volume, directory and file portions and returns an entire path. Under
288 Unix,
<code>$volume
</code> is ignored, and directory and file are concatenated. A '/' is
289 inserted if need be. On other OSes,
<code>$volume
</code> is significant.
</p>
293 $full_path = File::Spec-
>catpath( $volume, $directory, $file );
</pre>
296 <dt><strong><a name=
"item_abs2rel">abs2rel
</a></strong>
299 <p>Takes a destination path and an optional base path returns a relative path
300 from the base path to the destination path:
</p>
304 $rel_path = File::Spec-
>abs2rel( $path ) ;
305 $rel_path = File::Spec-
>abs2rel( $path, $base ) ;
</pre>
308 <p>If
<code>$base
</code> is not present or '', then
<a href=
"file://C|\msysgit\mingw\html/lib/Cwd.html">cwd()
</a> is used. If
<code>$base
</code> is
309 relative, then it is converted to absolute form using
310 <a href=
"#item_rel2abs">rel2abs()
</a>. This means that it is taken to be relative to
311 <a href=
"file://C|\msysgit\mingw\html/lib/Cwd.html">cwd()
</a>.
</p>
314 <p>On systems with the concept of volume, if
<code>$path
</code> and
<code>$base
</code> appear to be
315 on two different volumes, we will not attempt to resolve the two
316 paths, and we will instead simply return
<code>$path
</code>. Note that previous
317 versions of this module ignored the volume of
<code>$base
</code>, which resulted in
318 garbage results part of the time.
</p>
321 <p>On systems that have a grammar that indicates filenames, this ignores the
322 <code>$base
</code> filename as well. Otherwise all path components are assumed to be
326 <p>If
<code>$path
</code> is relative, it is converted to absolute form using
<a href=
"#item_rel2abs">rel2abs()
</a>.
327 This means that it is taken to be relative to
<a href=
"file://C|\msysgit\mingw\html/lib/Cwd.html">cwd()
</a>.
</p>
330 <p>No checks against the filesystem are made. On VMS, there is
331 interaction with the working environment, as logicals and
332 macros are expanded.
</p>
335 <p>Based on code written by Shigio Yamaguchi.
</p>
338 <dt><strong><a name=
"item_rel2abs"><code>rel2abs()
</code></a></strong>
341 <p>Converts a relative path to an absolute path.
</p>
345 $abs_path = File::Spec-
>rel2abs( $path ) ;
346 $abs_path = File::Spec-
>rel2abs( $path, $base ) ;
</pre>
349 <p>If
<code>$base
</code> is not present or '', then
<a href=
"file://C|\msysgit\mingw\html/lib/Cwd.html">cwd()
</a> is used. If
<code>$base
</code> is relative,
350 then it is converted to absolute form using
<a href=
"#item_rel2abs">rel2abs()
</a>. This means that it
351 is taken to be relative to
<a href=
"file://C|\msysgit\mingw\html/lib/Cwd.html">cwd()
</a>.
</p>
354 <p>On systems with the concept of volume, if
<code>$path
</code> and
<code>$base
</code> appear to be
355 on two different volumes, we will not attempt to resolve the two
356 paths, and we will instead simply return
<code>$path
</code>. Note that previous
357 versions of this module ignored the volume of
<code>$base
</code>, which resulted in
358 garbage results part of the time.
</p>
361 <p>On systems that have a grammar that indicates filenames, this ignores the
362 <code>$base
</code> filename as well. Otherwise all path components are assumed to be
366 <p>If
<code>$path
</code> is absolute, it is cleaned up and returned using
<a href=
"#item_canonpath">canonpath()
</a>.
</p>
369 <p>No checks against the filesystem are made. On VMS, there is
370 interaction with the working environment, as logicals and
371 macros are expanded.
</p>
374 <p>Based on code written by Shigio Yamaguchi.
</p>
378 <p>For further information, please see
<a href=
"file://C|\msysgit\mingw\html/lib/File/Spec/Unix.html">the File::Spec::Unix manpage
</a>,
379 <a href=
"file://C|\msysgit\mingw\html/lib/File/Spec/Mac.html">the File::Spec::Mac manpage
</a>,
<a href=
"file://C|\msysgit\mingw\html/lib/File/Spec/OS2.html">the File::Spec::OS2 manpage
</a>,
<a href=
"file://C|\msysgit\mingw\html/lib/File/Spec/Win32.html">the File::Spec::Win32 manpage
</a>, or
380 <a href=
"file://C|\msysgit\mingw\html/lib/File/Spec/VMS.html">the File::Spec::VMS manpage
</a>.
</p>
384 <h1><a name=
"see_also">SEE ALSO
</a></h1>
385 <p><a href=
"file://C|\msysgit\mingw\html/lib/File/Spec/Unix.html">the File::Spec::Unix manpage
</a>,
<a href=
"file://C|\msysgit\mingw\html/lib/File/Spec/Mac.html">the File::Spec::Mac manpage
</a>,
<a href=
"file://C|\msysgit\mingw\html/lib/File/Spec/OS2.html">the File::Spec::OS2 manpage
</a>,
386 <a href=
"file://C|\msysgit\mingw\html/lib/File/Spec/Win32.html">the File::Spec::Win32 manpage
</a>,
<a href=
"file://C|\msysgit\mingw\html/lib/File/Spec/VMS.html">the File::Spec::VMS manpage
</a>,
<a href=
"file://C|\msysgit\mingw\html/lib/File/Spec/Functions.html">the File::Spec::Functions manpage
</a>,
387 <a href=
"file://C|\msysgit\mingw\html/lib/ExtUtils/MakeMaker.html">the ExtUtils::MakeMaker manpage
</a></p>
391 <h1><a name=
"author">AUTHOR
</a></h1>
392 <p>Currently maintained by Ken Williams
<code><KWILLIAMS@cpan.org
></code>.
</p>
393 <p>The vast majority of the code was written by
394 Kenneth Albanowski
<code><kjahds@kjahds.com
></code>,
395 Andy Dougherty
<code><doughera@lafayette.edu
></code>,
396 Andreas K
önig
<code><A.Koenig@franz.ww.TU-Berlin.DE
></code>,
397 Tim Bunce
<code><Tim.Bunce@ig.co.uk
></code>.
398 VMS support by Charles Bailey
<code><bailey@newman.upenn.edu
></code>.
399 OS/
2 support by Ilya Zakharevich
<code><ilya@math.ohio-state.edu
></code>.
400 Mac support by Paul Schinder
<code><schinder@pobox.com
></code>, and
401 Thomas Wegner
<code><wegner_thomas@yahoo.com
></code>.
402 <a href=
"#item_abs2rel"><code>abs2rel()
</code></a> and
<a href=
"#item_rel2abs"><code>rel2abs()
</code></a> written by Shigio Yamaguchi
<code><shigio@tamacom.com
></code>,
403 modified by Barrie Slaymaker
<code><barries@slaysys.com
></code>.
404 splitpath(), splitdir(),
<a href=
"#item_catpath"><code>catpath()
</code></a> and
<a href=
"#item_catdir"><code>catdir()
</code></a> by Barrie Slaymaker.
</p>
408 <h1><a name=
"copyright">COPYRIGHT
</a></h1>
409 <p>Copyright (c)
2004 by the Perl
5 Porters. All rights reserved.
</p>
410 <p>This program is free software; you can redistribute it and/or modify
411 it under the same terms as Perl itself.
</p>
412 <table border=
"0" width=
"100%" cellspacing=
"0" cellpadding=
"3">
413 <tr><td class=
"block" style=
"background-color: #cccccc" valign=
"middle">
414 <big><strong><span class=
"block"> File::Spec - portably perform operations on file names
</span></strong></big>