Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

How do I get the full path for a file?

by Anonymous Monk
on Apr 13, 2000 at 23:59 UTC ( [id://7523]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question: (files)

Originally posted as a Categorized Question.

Replies are listed 'Best First'.
Re: How do I get the full path for a file?
by Fastolfe (Vicar) on Jun 22, 2002 at 23:44 UTC
    If you have a filename, then you probably already have some "relative" path to that filename, even if we're making the assumption that you're working from the current directory.

    In this case, File::Spec will do the job for you with its rel2abs function:

    $abs_path = File::Spec->rel2abs($filename);
    If you have a file but have no idea where it's located, you might want to use File::Find.
Re: how do I get fullpath for a file
by turnstep (Parson) on Apr 14, 2000 at 00:48 UTC

    Add this to the top of your code:

    use Cwd;

    Then you can just:

    $thisdir = cwd();

    This gets the directory the "safest" way. If you are definitely on unix, however, you can simply say:

    $thisdir = `pwd`;
    which is usually what Cwd does on unix systems. It has a few other options, such as fastcwd() and getcwd() but they are not used much. You can grab the name of the script itself by looking in $0 or even __FILE__.

    If you are doing it through the web, check out the environment variable 'SCRIPT_FILENAME'

    $pwd = $ENV{'SCRIPT_FILENAME'};

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (8)
As of 2024-04-19 15:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found