File::Spec
Native Rust implementation built into the interpreter. Runtime: PP. See original documentation for the full Perl reference.
Provides portable file path operations using Unix semantics.
Synopsis
use File::Spec;
my $path = File::Spec->catfile("usr", "local", "bin", "perl");
my $dir = File::Spec->catdir("usr", "local", "lib");
my ($vol, $dirs, $file) = File::Spec->splitpath($path);
my @dirs = File::Spec->splitdir($dirs);
my $abs = File::Spec->rel2abs("lib/Foo.pm");
my $rel = File::Spec->abs2rel("/usr/local/bin", "/usr");
Functions
abs2rel
Return a relative path from the base to the given path.
use File::Spec;
my $rel = File::Spec->abs2rel("/usr/local/bin", "/usr"); # "local/bin"
canonpath
Clean up a path by removing redundant separators and up-level references.
use File::Spec;
my $clean = File::Spec->canonpath("/foo//bar/../baz"); # "/foo/baz"
case_tolerant
Return false (0) on Unix, where the filesystem is case-sensitive.
catdir
Concatenate directory names to form a complete path.
use File::Spec;
my $dir = File::Spec->catdir("/usr", "local", "bin"); # "/usr/local/bin"
catfile
Concatenate directory names and a filename to form a complete path.
use File::Spec;
my $file = File::Spec->catfile("/usr", "local", "bin", "perl");
catpath
Combine volume, directory, and filename into a complete path (inverse of splitpath).
curdir
Return a string representation of the current directory (“.”).
devnull
Return the path to the null device (“/dev/null”).
file_name_is_absolute
Return true if the given path is absolute (starts with “/”).
join
Alias for catfile. Concatenate path components into a complete path.
Perl equivalent: File::Spec, File::Spec::Unix, File::Spec::Functions
no_upwards
Filter out “.” and “..” entries from a list of directory names.
path
Return the list of directories in the PATH environment variable.
rel2abs
Convert a relative path to an absolute path, optionally relative to a given base.
use File::Spec;
my $abs = File::Spec->rel2abs("lib/Foo.pm");
rootdir
Return a string representation of the root directory (“/”).
splitdir
Split a directory path into its component parts.
use File::Spec;
my @dirs = File::Spec->splitdir("/usr/local/bin"); # ("", "usr", "local", "bin")
splitpath
Split a path into volume, directory, and filename components.
use File::Spec;
my ($vol, $dir, $file) = File::Spec->splitpath("/usr/local/bin/perl");
tmpdir
Return the path to the system temporary directory (from $TMPDIR, $TEMP, $TMP, or “/tmp”).
updir
Return a string representation of the parent directory (“..”).