http://www.perlmonks.org?node_id=147195


in reply to Re: How do I get the directory containing a given file?
in thread How do I get the directory containing a given file?

use Cwd qw(abs_path); use File::Basename; my $dir = dirname(abs_path("../foo.html"));<BR> print "dir is ($dir)\n";

yields:

  opendir(../foo.html/..): Not a directory at text.pl line 4
  dir is ()

Other ideas?

Replies are listed 'Best First'.
Re: Re: Answer: How do I get the directory containing a given file?
by wog (Curate) on Feb 24, 2002 at 20:02 UTC
    It appears that Cwd::abs_path has issues in 5.6.1 (which seem to be fixed in bleedperl). You can get around this by reversing the calls:

    use Cwd qw(abs_path); use File::Basename; my $dir = abs_path(dirname($file));