4 use vars qw(@ISA $VERSION);
8 my %module = (MacOS => 'Mac',
13 NetWare => 'Win32', # Yes, File::Spec::Win32 works on NetWare.
14 dos => 'OS2', # Yes, File::Spec::OS2 works on DJGPP.
18 my $module = $module{$^O} || 'Unix';
20 require "File/Spec/$module.pm";
21 @ISA = ("File::Spec::$module");
29 File::Spec - portably perform operations on file names
35 $x=File::Spec->catfile('a', 'b', 'c');
37 which returns 'a/b/c' under Unix. Or:
39 use File::Spec::Functions;
41 $x = catfile('a', 'b', 'c');
45 This module is designed to support operations commonly performed on file
46 specifications (usually called "file names", but not to be confused with the
47 contents of a file, or Perl's file handles), such as concatenating several
48 directory and file names into a single path, or determining whether a path
49 is rooted. It is based on code directly taken from MakeMaker 5.17, code
50 written by Andreas KE<ouml>nig, Andy Dougherty, Charles Bailey, Ilya
51 Zakharevich, Paul Schinder, and others.
53 Since these functions are different for most operating systems, each set of
54 OS specific routines is available in a separate module, including:
62 The module appropriate for the current OS is automatically loaded by
63 File::Spec. Since some modules (like VMS) make use of facilities available
64 only under that OS, it may not be possible to load all modules under all
67 Since File::Spec is object oriented, subroutines should not be called directly,
70 File::Spec::catfile('a','b');
72 but rather as class methods:
74 File::Spec->catfile('a','b');
76 For simple uses, L<File::Spec::Functions> provides convenient functional
77 forms of these methods.
85 No physical check on the filesystem, but a logical cleanup of a
88 $cpath = File::Spec->canonpath( $path ) ;
92 Concatenate two or more directory names to form a complete path ending
93 with a directory. But remove the trailing slash from the resulting
94 string, because it doesn't look good, isn't necessary and confuses
95 OS2. Of course, if this is the root directory, don't cut off the
98 $path = File::Spec->catdir( @directories );
102 Concatenate one or more directory names and a filename to form a
103 complete path ending with a filename
105 $path = File::Spec->catfile( @directories, $filename );
109 Returns a string representation of the current directory.
111 $curdir = File::Spec->curdir();
115 Returns a string representation of the null device.
117 $devnull = File::Spec->devnull();
121 Returns a string representation of the root directory.
123 $rootdir = File::Spec->rootdir();
127 Returns a string representation of the first writable directory from a
128 list of possible temporary directories. Returns the current directory
129 if no writable temporary directories are found. The list of directories
130 checked depends on the platform; e.g. File::Spec::Unix checks $ENV{TMPDIR}
131 (unless taint is on) and /tmp.
133 $tmpdir = File::Spec->tmpdir();
137 Returns a string representation of the parent directory.
139 $updir = File::Spec->updir();
143 Given a list of file names, strip out those that refer to a parent
144 directory. (Does not strip symlinks, only '.', '..', and equivalents.)
146 @paths = File::Spec->no_upwards( @paths );
150 Returns a true or false value indicating, respectively, that alphabetic
151 is not or is significant when comparing file specifications.
153 $is_case_tolerant = File::Spec->case_tolerant();
155 =item file_name_is_absolute
157 Takes as argument a path and returns true if it is an absolute path.
159 $is_absolute = File::Spec->file_name_is_absolute( $path );
161 This does not consult the local filesystem on Unix, Win32, OS/2, or
162 Mac OS (Classic). It does consult the working environment for VMS
163 (see L<File::Spec::VMS/file_name_is_absolute>).
167 Takes no argument, returns the environment variable PATH (or the local
168 platform's equivalent) as a list.
170 @PATH = File::Spec->path();
174 join is the same as catfile.
178 Splits a path in to volume, directory, and filename portions. On systems
179 with no concept of volume, returns '' for volume.
181 ($volume,$directories,$file) = File::Spec->splitpath( $path );
182 ($volume,$directories,$file) = File::Spec->splitpath( $path, $no_file );
184 For systems with no syntax differentiating filenames from directories,
185 assumes that the last file is a path unless $no_file is true or a
186 trailing separator or /. or /.. is present. On Unix this means that $no_file
187 true makes this return ( '', $path, '' ).
189 The directory portion may or may not be returned with a trailing '/'.
191 The results can be passed to L</catpath()> to get back a path equivalent to
192 (usually identical to) the original path.
196 The opposite of L</catdir()>.
198 @dirs = File::Spec->splitdir( $directories );
200 $directories must be only the directory portion of the path on systems
201 that have the concept of a volume or that have path syntax that differentiates
202 files from directories.
204 Unlike just splitting the directories on the separator, empty
205 directory names (C<''>) can be returned, because these are significant
210 Takes volume, directory and file portions and returns an entire path. Under
211 Unix, $volume is ignored, and directory and file are concatenated. A '/' is
212 inserted if need be. On other OSs, $volume is significant.
214 $full_path = File::Spec->catpath( $volume, $directory, $file );
218 Takes a destination path and an optional base path returns a relative path
219 from the base path to the destination path:
221 $rel_path = File::Spec->abs2rel( $path ) ;
222 $rel_path = File::Spec->abs2rel( $path, $base ) ;
224 If $base is not present or '', then L<cwd()|Cwd> is used. If $base is
225 relative, then it is converted to absolute form using
226 L</rel2abs()>. This means that it is taken to be relative to
229 On systems with the concept of volume, if $path and $base appear to be
230 on two different volumes, we will not attempt to resolve the two
231 paths, and we will instead simply return $path. Note that previous
232 versions of this module ignored the volume of $base, which resulted in
233 garbage results part of the time.
235 On systems that have a grammar that indicates filenames, this ignores the
236 $base filename as well. Otherwise all path components are assumed to be
239 If $path is relative, it is converted to absolute form using L</rel2abs()>.
240 This means that it is taken to be relative to L<cwd()|Cwd>.
242 No checks against the filesystem are made. On VMS, there is
243 interaction with the working environment, as logicals and
246 Based on code written by Shigio Yamaguchi.
250 Converts a relative path to an absolute path.
252 $abs_path = File::Spec->rel2abs( $path ) ;
253 $abs_path = File::Spec->rel2abs( $path, $base ) ;
255 If $base is not present or '', then L<cwd()|Cwd> is used. If $base is relative,
256 then it is converted to absolute form using L</rel2abs()>. This means that it
257 is taken to be relative to L<cwd()|Cwd>.
259 On systems with the concept of volume, if $path and $base appear to be
260 on two different volumes, we will not attempt to resolve the two
261 paths, and we will instead simply return $path. Note that previous
262 versions of this module ignored the volume of $base, which resulted in
263 garbage results part of the time.
265 On systems that have a grammar that indicates filenames, this ignores the
266 $base filename as well. Otherwise all path components are assumed to be
269 If $path is absolute, it is cleaned up and returned using L</canonpath()>.
271 No checks against the filesystem are made. On VMS, there is
272 interaction with the working environment, as logicals and
275 Based on code written by Shigio Yamaguchi.
279 For further information, please see L<File::Spec::Unix>,
280 L<File::Spec::Mac>, L<File::Spec::OS2>, L<File::Spec::Win32>, or
285 L<File::Spec::Unix>, L<File::Spec::Mac>, L<File::Spec::OS2>,
286 L<File::Spec::Win32>, L<File::Spec::VMS>, L<File::Spec::Functions>,
287 L<ExtUtils::MakeMaker>
291 Kenneth Albanowski <kjahds@kjahds.com>, Andy Dougherty
292 <doughera@lafayette.edu>, Andreas KE<ouml>nig
293 <A.Koenig@franz.ww.TU-Berlin.DE>, Tim Bunce <Tim.Bunce@ig.co.uk.
294 VMS support by Charles Bailey <bailey@newman.upenn.edu>.
295 OS/2 support by Ilya Zakharevich <ilya@math.ohio-state.edu>.
296 Mac support by Paul Schinder <schinder@pobox.com>, and Thomas Wegner
297 <wegner_thomas@yahoo.com>. abs2rel() and rel2abs() written by Shigio
298 Yamaguchi <shigio@tamacom.com>, modified by Barrie Slaymaker
299 <barries@slaysys.com>. splitpath(), splitdir(), catpath() and
300 catdir() by Barrie Slaymaker.