Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

File path

by Rijwan (Novice)
on Jan 19, 2009 at 10:19 UTC ( [id://737241]=perlquestion: print w/replies, xml ) Need Help??

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

Can anybody tell me function/code which returns full file path if the file exists.For example i want to full path of notepad.exe.

Replies are listed 'Best First'.
Re: File path
by prasadbabu (Prior) on Jan 19, 2009 at 10:29 UTC

    Please see the module File::Which.

    use strict; use warnings; use File::Which; my $path = which('notepad.exe'); print $path; output: ------- C:\WINDOWS\system32\notepad.exe

    update: It will search only executable files, not all files. :-(

    Prasad

Re: File path
by Corion (Patriarch) on Jan 19, 2009 at 10:29 UTC

    notepad.exe will always be at $ENV{WINDIR}\notepad.exe. Otherwise, I'm not aware of a module that searches $ENV{PATH} for an executable, but File::Spec together with the -x operator will do.

Re: File path
by puudeli (Pilgrim) on Jan 19, 2009 at 10:30 UTC
    Maybe File::Find or File::Spec could help you depending on what you know about the path in advance?
    --
    seek $her, $from, $everywhere if exists $true{love};
Re: File path
by cdarke (Prior) on Jan 19, 2009 at 12:19 UTC
Re: File path
by almut (Canon) on Jan 19, 2009 at 10:29 UTC
    use Cwd 'abs_path'; my $path = abs_path($file);

    (Update: though, reading the other replies, I may have misunderstood the question...)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://737241]
Approved by moritz
Front-paged by Arunbear
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: (4)
As of 2024-03-19 05:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found