PathTools-3.30 > File::Spec

名前

File::Spec - portably perform operations on file names

File::Spec - ファイル名に関して移植性のある操作を行う

概要

        use File::Spec;

        $x=File::Spec->catfile('a', 'b', 'c');

which returns 'a/b/c' under Unix. Or:

これは Unix では 'a/b/c' を返します。 あるいは:

        use File::Spec::Functions;

        $x = catfile('a', 'b', 'c');

説明

This module is designed to support operations commonly performed on file specifications (usually called "file names", but not to be confused with the contents of a file, or Perl's file handles), such as concatenating several directory and file names into a single path, or determining whether a path is rooted. It is based on code directly taken from MakeMaker 5.17, code written by Andreas König, Andy Dougherty, Charles Bailey, Ilya Zakharevich, Paul Schinder, and others.

このモジュールは、ファイル指定 (file specifications) (通常「ファイル名」と 呼ばれますが、ファイルの内容やPerl のファイルハンドルと 混同しないようにしてください) に対して、 複数のディレクトリとファイル名の単一のパスへの結合、 パスがルートからかの決定、といった一般的に行われる操作に 対応するために設計されています。 これは Andreas König, Andy Dougherty, Charles Bailey, Ilya Zakharevich, Paul Schinder などによって書かれた MakeMaker 5.17 から 直接コードを取っています。

Since these functions are different for most operating systems, each set of OS specific routines is available in a separate module, including:

これらの関数はほとんどのオペレーティングシステムによって異なるので、 それぞれの OS 固有のルーチンは次のような別々のモジュールで利用可能です:

        File::Spec::Unix
        File::Spec::Mac
        File::Spec::OS2
        File::Spec::Win32
        File::Spec::VMS

The module appropriate for the current OS is automatically loaded by File::Spec. Since some modules (like VMS) make use of facilities available only under that OS, it may not be possible to load all modules under all operating systems.

現在の OS のための適切なモジュールは File::Spec によって自動的に 読み込まれます。 (VMS のような) 一部のモジュールはその OS でのみ利用可能な機能を 使っているので、全てのオペレーティングシステムで全てのモジュールが 読み込まれるわけではありません。

Since File::Spec is object oriented, subroutines should not be called directly, as in:

File::Spec はオブジェクト指向なので、サブルーチンは次のように 直接呼び出されるべきではありません:

        File::Spec::catfile('a','b');

but rather as class methods:

次のようにクラスメソッドとして呼び出してください:

        File::Spec->catfile('a','b');

For simple uses, File::Spec::Functions provides convenient functional forms of these methods.

単純な用途のために、File::Spec::Functions がこれらのメソッドの便利な 関数形式を提供します。

メソッド

canonpath

No physical check on the filesystem, but a logical cleanup of a path.

ファイルシステムでの物理的なチェックはせずに、パスを論理的に整理します。

    $cpath = File::Spec->canonpath( $path ) ;

Note that this does *not* collapse x/../y sections into y. This is by design. If /foo on your system is a symlink to /bar/baz, then /foo/../quux is actually /bar/quux, not /quux as a naive ../-removal would give you. If you want to do this kind of processing, you probably want Cwd's realpath() function to actually traverse the filesystem cleaning up paths like this.

これは x/../yy に短縮「しない」ことに注意してください。 これは仕様です。 あなたのシステムでの /foo/bar/baz へのシンボリックリンクの場合、 /foo/../quux は、単純に ../ を削除した結果となる /quux ではなく、 実際には /bar/quux となります。 このような処理をしたい場合は、このようなパスを実際にファイルシステムを たどって整理する Cwdrealpath() を使うべきでしょう。

catdir

Concatenate two or more directory names to form a complete path ending with a directory. But remove the trailing slash from the resulting string, because it doesn't look good, isn't necessary and confuses OS/2. Of course, if this is the root directory, don't cut off the trailing slash :-)

二つ以上のディレクトリ名を、ディレクトリで終わる完全なパスの形に 結合します。 しかし、結果の文字列の末尾のスラッシュは削除されます; 見た目が良くなく、不要であり、OS/2 を混乱させるからです。 もちろん、これがルートディレクトリの場合は、末尾のスラッシュは 削除されません :-)

    $path = File::Spec->catdir( @directories );
catfile

Concatenate one or more directory names and a filename to form a complete path ending with a filename

一つ以上のディレクトリ名とファイル名を、ファイル名で終わる 完全なパスの形に結合します。

    $path = File::Spec->catfile( @directories, $filename );
curdir

Returns a string representation of the current directory.

カレントディレクトリの文字列表現を返します。

    $curdir = File::Spec->curdir();
devnull

Returns a string representation of the null device.

ヌルデバイスの文字列表現を返します。

    $devnull = File::Spec->devnull();
rootdir

Returns a string representation of the root directory.

ルートディレクトリの文字列表現を返します。

    $rootdir = File::Spec->rootdir();
tmpdir

Returns a string representation of the first writable directory from a list of possible temporary directories. Returns the current directory if no writable temporary directories are found. The list of directories checked depends on the platform; e.g. File::Spec::Unix checks $ENV{TMPDIR} (unless taint is on) and /tmp.

一時ディレクトリの候補の一覧から最初の書き込み可能ディレクトリの 文字列表現を返します。 もし書き込み可能な一時ディレクトリが見つからなかった場合は カレントディレクトリを返します。 チェックされるディレクトリの一覧はプラットフォームに依存します; 例えば、File::Spec::Unix は $ENV{TMPDIR} (汚染チェックがオンでない場合)と /tmp をチェックします。

    $tmpdir = File::Spec->tmpdir();
updir

Returns a string representation of the parent directory.

親ディレクトリの文字列表現を返します。

    $updir = File::Spec->updir();
no_upwards

Given a list of file names, strip out those that refer to a parent directory. (Does not strip symlinks, only '.', '..', and equivalents.)

ファイル名のリストを取って、親ディレクトリを参照しているものを 取り除きます。 (シンボリックリンクは取り除きません; '.', '..' および等価物のみです。)

    @paths = File::Spec->no_upwards( @paths );
case_tolerant

Returns a true or false value indicating, respectively, that alphabetic case is not or is significant when comparing file specifications.

ファイル指定を比較するときに、英字の大文字小文字を認識するかどうかを示す 真または偽の値を返します。

    $is_case_tolerant = File::Spec->case_tolerant();
file_name_is_absolute

Takes as its argument a path, and returns true if it is an absolute path.

パスを引数として取り、これが絶対パスの場合に真を返します。

    $is_absolute = File::Spec->file_name_is_absolute( $path );

This does not consult the local filesystem on Unix, Win32, OS/2, or Mac OS (Classic). It does consult the working environment for VMS (see "file_name_is_absolute" in File::Spec::VMS).

これは、Unix, Win32, OS/2, Mac OS (Classic) ではローカルのファイルシステムを 参照しません。 VMS の動作環境では参照します ("file_name_is_absolute" in File::Spec::VMS を 参照してください)。

path

Takes no argument. Returns the environment variable PATH (or the local platform's equivalent) as a list.

引数を取りません。 PATH 環境変数 (またはローカルなプラットフォームでの等価物) を リストとして返します。

    @PATH = File::Spec->path();
join

join is the same as catfile.

join は catfile と同じです。

splitpath

Splits a path in to volume, directory, and filename portions. On systems with no concept of volume, returns '' for volume.

パスをボリューム、ディレクトリ、ファイル名の部分に分割します。 ボリュームの概念がないシステムでは、ボリュームとして '' を返します。

    ($volume,$directories,$file) = File::Spec->splitpath( $path );
    ($volume,$directories,$file) = File::Spec->splitpath( $path, $no_file );

For systems with no syntax differentiating filenames from directories, assumes that the last file is a path unless $no_file is true or a trailing separator or /. or /.. is present. On Unix, this means that $no_file true makes this return ( '', $path, '' ).

ファイル名とディレクトリに文法上の違いがないシステムでは、 $no_file が真であったり末尾の区切り文字や /. or /.. があったり、 ということがなければ、最後のファイルがパスであると仮定します。 Unix では、$no_file が真の場合、これは ( '', $path, '' ) を 返すということです。

The directory portion may or may not be returned with a trailing '/'.

ディレクトリ部は末尾の '/' があるかもしれませんしないかもしれません。

The results can be passed to "catpath()" to get back a path equivalent to (usually identical to) the original path.

結果は、元のパスと等価な (通常は同じ) パスを取り戻すために "catpath()" に渡せます。

splitdir

The opposite of "catdir()".

"catdir()" の逆です。

    @dirs = File::Spec->splitdir( $directories );

$directories must be only the directory portion of the path on systems that have the concept of a volume or that have path syntax that differentiates files from directories.

ボリュームの概念があるか、ファイルとディレクトリに違いがあるパス文法の システムの場合、$directories はパスの唯一の ディレクトリ部でなければなりません。

Unlike just splitting the directories on the separator, empty directory names ('') can be returned, because these are significant on some OSes.

単にディレクトリを区切り文字で分割するのと異なり、空ディレクトリ名 ('') が返されることがあります; 一部の OS ではこれが意味を持つからです。

catpath()

Takes volume, directory and file portions and returns an entire path. Under Unix, $volume is ignored, and directory and file are concatenated. A '/' is inserted if need be. On other OSes, $volume is significant.

ボリューム、ディレクトリ、ファイル部を取って、パス全体を返します。 Unix では、$volume は無視され、ディレクトリとファイルは結合されます。 必要な場合は '/' が挿入されます。 その他の OS では、$volume は意味を持ちます。

    $full_path = File::Spec->catpath( $volume, $directory, $file );
abs2rel

Takes a destination path and an optional base path returns a relative path from the base path to the destination path:

目標パスとオプションの基底パスを取って、基底パスから目標パスへの 相対パスを返します:

    $rel_path = File::Spec->abs2rel( $path ) ;
    $rel_path = File::Spec->abs2rel( $path, $base ) ;

If $base is not present or '', then Cwd::cwd() is used. If $base is relative, then it is converted to absolute form using "rel2abs()". This means that it is taken to be relative to Cwd::cwd().

$base が存在しないか '' の場合、Cwd::cwd() が使われます。 $base が相対の場合、"rel2abs()" を使って絶対形式に変換されます。 つまり、Cwd::cwd() からの相対パスになります。

On systems with the concept of volume, if $path and $base appear to be on two different volumes, we will not attempt to resolve the two paths, and we will instead simply return $path. Note that previous versions of this module ignored the volume of $base, which resulted in garbage results part of the time.

ボリュームの概念があるシステムでは、$path$base に異なった ボリュームがあるように見える場合、二つのパスを解決しようとせずに、 単に $path を返します。 このモジュールの以前のバージョンでは、$base のボリュームを 無視していたため、一時期壊れた結果を返していました。

On systems that have a grammar that indicates filenames, this ignores the $base filename as well. Otherwise all path components are assumed to be directories.

ファイル名を示す文法がある場合、$base ファイル名も無視されます。 さもなければ全てのパス要素はディレクトリであると仮定されます。

If $path is relative, it is converted to absolute form using "rel2abs()". This means that it is taken to be relative to Cwd::cwd().

$path が相対の場合、"rel2abs()" を使って絶対形式に変換されます。 つまり、Cwd::cwd() からの相対パスとなります。

No checks against the filesystem are made. On VMS, there is interaction with the working environment, as logicals and macros are expanded.

ファイルシステムがあるかどうかのチェックは行いません。 VMS では、論理とマクロが拡張されるので、動作環境との相互作用があります。

Based on code written by Shigio Yamaguchi.

Shigio Yamaguchi が書いたコードを基にしています。

rel2abs()

Converts a relative path to an absolute path.

相対パスを絶対パスに変換します。

    $abs_path = File::Spec->rel2abs( $path ) ;
    $abs_path = File::Spec->rel2abs( $path, $base ) ;

If $base is not present or '', then Cwd::cwd() is used. If $base is relative, then it is converted to absolute form using "rel2abs()". This means that it is taken to be relative to Cwd::cwd().

$base が存在しないか '' の場合、Cwd::cwd() が使われます。 $base が相対の場合、"rel2abs()" を使って絶対形式に変換されます。 つまり、Cwd::cwd() からの相対パスとなります。

On systems with the concept of volume, if $path and $base appear to be on two different volumes, we will not attempt to resolve the two paths, and we will instead simply return $path. Note that previous versions of this module ignored the volume of $base, which resulted in garbage results part of the time.

ボリュームの概念があるシステムでは、$path$base に異なった ボリュームがあるように見える場合、二つのパスを解決しようとせずに、 単に $path を返します。 このモジュールの以前のバージョンでは、$base のボリュームを 無視していたため、一時期壊れた結果を返していました。

On systems that have a grammar that indicates filenames, this ignores the $base filename as well. Otherwise all path components are assumed to be directories.

ファイル名を示す文法がある場合、$base ファイル名も無視されます。 さもなければ全てのパス要素はディレクトリであると仮定されます。

If $path is absolute, it is cleaned up and returned using "canonpath()".

$path が絶対パスの場合、"canonpath()" を使って整理したものを返します。

No checks against the filesystem are made. On VMS, there is interaction with the working environment, as logicals and macros are expanded.

ファイルシステムがあるかどうかのチェックは行いません。 VMS では、論理とマクロが拡張されるので、動作環境との相互作用があります。

Based on code written by Shigio Yamaguchi.

Shigio Yamaguchi が書いたコードを基にしています。

さらなる情報については、File::Spec::Unix, File::Spec::Mac, File::Spec::OS2, File::Spec::Win32, File::Spec::VMS を参照してください。

SEE ALSO

File::Spec::Unix, File::Spec::Mac, File::Spec::OS2, File::Spec::Win32, File::Spec::VMS, File::Spec::Functions, ExtUtils::MakeMaker

作者

Currently maintained by Ken Williams <KWILLIAMS@cpan.org>.

現在のところ Ken Williams <KWILLIAMS@cpan.org> によって 保守されています。

The vast majority of the code was written by Kenneth Albanowski <kjahds@kjahds.com>, Andy Dougherty <doughera@lafayette.edu>, Andreas König <A.Koenig@franz.ww.TU-Berlin.DE>, Tim Bunce <Tim.Bunce@ig.co.uk>. VMS support by Charles Bailey <bailey@newman.upenn.edu>. OS/2 support by Ilya Zakharevich <ilya@math.ohio-state.edu>. Mac support by Paul Schinder <schinder@pobox.com>, and Thomas Wegner <wegner_thomas@yahoo.com>. abs2rel() and rel2abs() written by Shigio Yamaguchi <shigio@tamacom.com>, modified by Barrie Slaymaker <barries@slaysys.com>. splitpath(), splitdir(), catpath() and catdir() by Barrie Slaymaker.

大部分のコードは Kenneth Albanowski <kjahds@kjahds.com>, Andy Dougherty <doughera@lafayette.edu>, Andreas König <A.Koenig@franz.ww.TU-Berlin.DE>, Tim Bunce <Tim.Bunce@ig.co.uk> によって書かれました。 VMS 対応は Charles Bailey <bailey@newman.upenn.edu> によるものです。 OS/2 対応は Ilya Zakharevich <ilya@math.ohio-state.edu> による ものです。 Mac 対応は Paul Schinder <schinder@pobox.com> と Thomas Wegner <wegner_thomas@yahoo.com> によるものです。 abs2rel() と rel2abs() は Shigio Yamaguchi <shigio@tamacom.com> によって書かれ、 Barrie Slaymaker <barries@slaysys.com> によって修正されました。 splitpath(), splitdir(), catpath() and catdir() は Barrie Slaymaker によるものです。

コピーライト

Copyright (c) 2004 by the Perl 5 Porters. All rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.