{
    "mode": "perldoc",
    "parameter": "File::Spec",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/File%3A%3ASpec/json",
    "generated": "2026-10-04T06:42:34Z",
    "synopsis": "use File::Spec;\nmy $x = File::Spec->catfile('a', 'b', 'c');\nwhich returns 'a/b/c' under Unix. Or:\nuse File::Spec::Functions;\nmy $x = catfile('a', 'b', 'c');",
    "sections": {
        "NAME": {
            "content": "File::Spec - portably perform operations on file names\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use File::Spec;\n\nmy $x = File::Spec->catfile('a', 'b', 'c');\n\nwhich returns 'a/b/c' under Unix. Or:\n\nuse File::Spec::Functions;\n\nmy $x = catfile('a', 'b', 'c');\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "This module is designed to support operations commonly performed on file specifications (usually\ncalled \"file names\", but not to be confused with the contents of a file, or Perl's file\nhandles), such as concatenating several directory and file names into a single path, or\ndetermining whether a path is rooted. It is based on code directly taken from MakeMaker 5.17,\ncode written by Andreas König, Andy Dougherty, Charles Bailey, Ilya Zakharevich, Paul Schinder,\nand others.\n\nSince these functions are different for most operating systems, each set of OS specific routines\nis available in a separate module, including:\n\nFile::Spec::Unix\nFile::Spec::Mac\nFile::Spec::OS2\nFile::Spec::Win32\nFile::Spec::VMS\n\nThe module appropriate for the current OS is automatically loaded by File::Spec. Since some\nmodules (like VMS) make use of facilities available only under that OS, it may not be possible\nto load all modules under all operating systems.\n\nSince File::Spec is object oriented, subroutines should not be called directly, as in:\n\nFile::Spec::catfile('a','b');\n\nbut rather as class methods:\n\nFile::Spec->catfile('a','b');\n\nFor simple uses, File::Spec::Functions provides convenient functional forms of these methods.\n",
            "subsections": []
        },
        "METHODS": {
            "content": "canonpath\nNo physical check on the filesystem, but a logical cleanup of a path.\n\n$cpath = File::Spec->canonpath( $path ) ;\n\nNote that this does *not* collapse x/../y sections into y. This is by design. If /foo on your\nsystem is a symlink to /bar/baz, then /foo/../quux is actually /bar/quux, not /quux as a naive\n../-removal would give you. If you want to do this kind of processing, you probably want\n\"Cwd\"'s realpath() function to actually traverse the filesystem cleaning up paths like this.\n\ncatdir\nConcatenate two or more directory names to form a complete path ending with a directory. But\nremove the trailing slash from the resulting string, because it doesn't look good, isn't\nnecessary and confuses OS/2. Of course, if this is the root directory, don't cut off the\ntrailing slash :-)\n\n$path = File::Spec->catdir( @directories );\n\ncatfile\nConcatenate one or more directory names and a filename to form a complete path ending with a\nfilename\n\n$path = File::Spec->catfile( @directories, $filename );\n\ncurdir\nReturns a string representation of the current directory.\n\n$curdir = File::Spec->curdir();\n\ndevnull\nReturns a string representation of the null device.\n\n$devnull = File::Spec->devnull();\n\nrootdir\nReturns a string representation of the root directory.\n\n$rootdir = File::Spec->rootdir();\n\ntmpdir\nReturns a string representation of the first writable directory from a list of possible\ntemporary directories. Returns the current directory if no writable temporary directories are\nfound. The list of directories checked depends on the platform; e.g. File::Spec::Unix checks\n$ENV{TMPDIR} (unless taint is on) and /tmp.\n\n$tmpdir = File::Spec->tmpdir();\n\nupdir\nReturns a string representation of the parent directory.\n\n$updir = File::Spec->updir();\n\nnoupwards\nGiven a list of files in a directory (such as from readdir()), strip out '.' and '..'.\n\nSECURITY NOTE: This does NOT filter paths containing '..', like '../../../../etc/passwd', only\nliteral matches to '.' and '..'.\n\n@paths = File::Spec->noupwards( readdir $dirhandle );\n\ncasetolerant\nReturns a true or false value indicating, respectively, that alphabetic case is not or is\nsignificant when comparing file specifications. Cygwin and Win32 accept an optional drive\nargument.\n\n$iscasetolerant = File::Spec->casetolerant();\n\nfilenameisabsolute\nTakes as its argument a path, and returns true if it is an absolute path.\n\n$isabsolute = File::Spec->filenameisabsolute( $path );\n\nThis does not consult the local filesystem on Unix, Win32, OS/2, or Mac OS (Classic). It does\nconsult the working environment for VMS (see \"filenameisabsolute\" in File::Spec::VMS).\n\npath\nTakes no argument. Returns the environment variable \"PATH\" (or the local platform's\nequivalent) as a list.\n\n@PATH = File::Spec->path();\n\njoin\njoin is the same as catfile.\n\nsplitpath\nSplits a path in to volume, directory, and filename portions. On systems with no concept of\nvolume, returns '' for volume.\n\n($volume,$directories,$file) =\nFile::Spec->splitpath( $path );\n($volume,$directories,$file) =\nFile::Spec->splitpath( $path, $nofile );\n\nFor systems with no syntax differentiating filenames from directories, assumes that the last\nfile is a path unless $nofile is true or a trailing separator or /. or /.. is present. On\nUnix, this means that $nofile true makes this return ( '', $path, '' ).\n\nThe directory portion may or may not be returned with a trailing '/'.\n\nThe results can be passed to \"catpath()\" to get back a path equivalent to (usually identical\nto) the original path.\n\nsplitdir\nThe opposite of \"catdir\".\n\n@dirs = File::Spec->splitdir( $directories );\n\n$directories must be only the directory portion of the path on systems that have the concept\nof a volume or that have path syntax that differentiates files from directories.\n\nUnlike just splitting the directories on the separator, empty directory names ('') can be\nreturned, because these are significant on some OSes.\n",
            "subsections": [
                {
                    "name": "catpath",
                    "content": "Takes volume, directory and file portions and returns an entire path. Under Unix, $volume is\nignored, and directory and file are concatenated. A '/' is inserted if need be. On other OSes,\n$volume is significant.\n\n$fullpath = File::Spec->catpath( $volume, $directory, $file );\n\nabs2rel\nTakes a destination path and an optional base path returns a relative path from the base path\nto the destination path:\n\n$relpath = File::Spec->abs2rel( $path ) ;\n$relpath = File::Spec->abs2rel( $path, $base ) ;\n\nIf $base is not present or '', then Cwd::cwd() is used. If $base is relative, then it is\nconverted to absolute form using \"rel2abs()\". This means that it is taken to be relative to\nCwd::cwd().\n\nOn systems with the concept of volume, if $path and $base appear to be on two different\nvolumes, we will not attempt to resolve the two paths, and we will instead simply return\n$path. Note that previous versions of this module ignored the volume of $base, which resulted\nin garbage results part of the time.\n\nOn systems that have a grammar that indicates filenames, this ignores the $base filename as\nwell. Otherwise all path components are assumed to be directories.\n\nIf $path is relative, it is converted to absolute form using \"rel2abs()\". This means that it\nis taken to be relative to Cwd::cwd().\n\nNo checks against the filesystem are made. On VMS, there is interaction with the working\nenvironment, as logicals and macros are expanded.\n\nBased on code written by Shigio Yamaguchi.\n"
                },
                {
                    "name": "rel2abs",
                    "content": "Converts a relative path to an absolute path.\n\n$abspath = File::Spec->rel2abs( $path ) ;\n$abspath = File::Spec->rel2abs( $path, $base ) ;\n\nIf $base is not present or '', then Cwd::cwd() is used. If $base is relative, then it is\nconverted to absolute form using \"rel2abs()\". This means that it is taken to be relative to\nCwd::cwd().\n\nOn systems with the concept of volume, if $path and $base appear to be on two different\nvolumes, we will not attempt to resolve the two paths, and we will instead simply return\n$path. Note that previous versions of this module ignored the volume of $base, which resulted\nin garbage results part of the time.\n\nOn systems that have a grammar that indicates filenames, this ignores the $base filename as\nwell. Otherwise all path components are assumed to be directories.\n\nIf $path is absolute, it is cleaned up and returned using \"canonpath\".\n\nNo checks against the filesystem are made. On VMS, there is interaction with the working\nenvironment, as logicals and macros are expanded.\n\nBased on code written by Shigio Yamaguchi.\n\nFor further information, please see File::Spec::Unix, File::Spec::Mac, File::Spec::OS2,\nFile::Spec::Win32, or File::Spec::VMS.\n"
                }
            ]
        },
        "SEE ALSO": {
            "content": "File::Spec::Unix, File::Spec::Mac, File::Spec::OS2, File::Spec::Win32, File::Spec::VMS,\nFile::Spec::Functions, ExtUtils::MakeMaker\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Maintained by perl5-porters <perl5-porters@perl.org>.\n\nThe vast majority of the code was written by Kenneth Albanowski \"<kjahds@kjahds.com>\", Andy\nDougherty \"<doughera@lafayette.edu>\", Andreas König \"<A.Koenig@franz.ww.TU-Berlin.DE>\", Tim\nBunce \"<Tim.Bunce@ig.co.uk>\". VMS support by Charles Bailey \"<bailey@newman.upenn.edu>\". OS/2\nsupport by Ilya Zakharevich \"<ilya@math.ohio-state.edu>\". Mac support by Paul Schinder\n\"<schinder@pobox.com>\", and Thomas Wegner \"<wegnerthomas@yahoo.com>\". abs2rel() and rel2abs()\nwritten by Shigio Yamaguchi \"<shigio@tamacom.com>\", modified by Barrie Slaymaker\n\"<barries@slaysys.com>\". splitpath(), splitdir(), catpath() and catdir() by Barrie Slaymaker.\n",
            "subsections": []
        },
        "COPYRIGHT": {
            "content": "Copyright (c) 2004-2013 by the Perl 5 Porters. All rights reserved.\n\nThis program is free software; you can redistribute it and/or modify it under the same terms as\nPerl itself.\n",
            "subsections": []
        }
    },
    "summary": "File::Spec - portably perform operations on file names",
    "flags": [],
    "examples": [],
    "see_also": []
}