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