Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

how to check

by Anonymous Monk
on May 23, 2009 at 07:30 UTC ( [id://765805]=perlquestion: print w/replies, xml ) Need Help??

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

beginner question: how to check whether the given input is a file or folder ?
if -f $path { do something }
is it correct , i need to check the given path is a file or folder ?

Replies are listed 'Best First'.
Re: how to check
by balakrishnan (Monk) on May 23, 2009 at 08:52 UTC
    if (-f $ARGV[0]) { print "file"; } elsif(-d $ARGV[0]) { print "dir"; }
    -f option is used to check whether the argument is a file or not.
    -d option is used to check whether the argument is a directory or not.
Re: how to check
by ig (Vicar) on May 23, 2009 at 08:43 UTC

    Your test will be true if $path is the path of a file. You can use '-d' to test if it is the path of a directory. Too see all the tests you can read -X

Re: how to check
by Anonymous Monk on May 23, 2009 at 08:42 UTC

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2024-04-26 06:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found