Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

checking for a file

by splitOnce (Acolyte)
on Aug 02, 2002 at 13:53 UTC ( [id://187087]=perlquestion: print w/replies, xml ) Need Help??

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

Hello guys, I know this is an easy one but since I am new , I would have problems like this : I need to check weather a file exists or not under a certain directory ,, the file
$targetFile = "theFile"
and I know the directory as well,
/bin/do/foo
so I need to know if it exists under foo, knowing that I am not under foo when searching for that file or I could be as well, I tried the -e and local but don't seem to work ,, thanks for hints on this one .

Replies are listed 'Best First'.
Re: checking for a file
by dada (Chaplain) on Aug 02, 2002 at 14:02 UTC
    if(-e "/bin/do/foo/$targetFile") { print "is there!\n"; } else { print "someone stoled it...\n"; }
    cheers,
    Aldo
    __END__ $_=q,just perl,,s, , another ,,s,$, hacker,,print;
      I'd rather go with
      if(-f "/bin/do/foo/$targetFile") { print "is there!\n"; } else { print "someone stoled it...\n"; }
      to check if it's actually a file (that exists), as the -e may also return true on a directory.
        Thanks all , I was able to figure it out with the -f ,, thank you again
Re: checking for a file
by dreadpiratepeter (Priest) on Aug 02, 2002 at 14:01 UTC
    What's wrong with:
    my $exists = -e "/bin/do/foo/$theFile";



    -pete
    "Pain heals. Chicks dig scars. Glory lasts forever."

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (2)
As of 2024-04-25 02:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found