etcshadow has asked for the wisdom of the Perl Monks concerning the following question:

Is there a good, cross-platform portable method or module for identifying pseudo directories like "." and ".."? I've done a good deal of looking around, and can't seem to find anything much.

About the best that I have come up with so far is a snippet from the latest version of File::Find off of CPAN which is basically like:

$File::Find::skip_pattern = qr/^\.{1,2}\z/; if ($^O eq 'MacOS') { $File::Find::skip_pattern = qr/^Icon\015\z/; }
Anyone know anything better/safer, or at least more canonical?
------------ :Wq Not an editor command: Wq

Replies are listed 'Best First'.
Re: Portable method for ignoring psuedo-files/psuedo-dirs?
by chromatic (Archbishop) on Mar 06, 2004 at 05:53 UTC

    Look at File::Spec's no_upwards(). There's an also updir(), but I don't see something like this_dir().

    Update: Oh yeah, curdir()!

      There's a curdir() which will do what you want.

      My test code:

      use File::Spec; my $f = 'File::Spec'; print $f->curdir, "\n"; print $f->updir, "\n";

      My output:

      $ perl ./test_file_spec . .. $

      There's also some notes on this in the perlport manpage ("Files and Filesystems" section).

      PN5

      Thanks, no_upwards is exactly what I was looking for. I don't know how I missed it, considering that I looked through File::Spec several times, and am using it already for the other file-system-portable functions.

      Anyway, thanks.

      ------------ :Wq Not an editor command: Wq