Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: How do I get the directory containing a given file?

by wog (Curate)
on Feb 24, 2002 at 18:48 UTC ( #147191=note: print w/ replies, xml ) Need Help??


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

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

Turning this into a complete perl program is left as an exercise to the reader.


Comment on Re: How do I get the directory containing a given file?
Download Code
Replies are listed 'Best First'.
Re: Answer: How do I get the directory containing a given file?
by mobiGeek (Beadle) on Feb 24, 2002 at 19:19 UTC
    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?

      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));

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://147191]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (17)
As of 2015-07-31 14:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (278 votes), past polls