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

Re: how to know if a path exists or not

by tobyink (Abbot)
on Oct 11, 2012 at 15:11 UTC ( #998472=note: print w/ replies, xml ) Need Help??


in reply to how to know if a path exists or not

There is a group of built-in Perl functions to do this sort of thing (checking the existence of files, whether they're readable/writeable/executable, whether they're directories, files or something else, etc). This group of functions is unusual in that their names all begin with a hyphen; usually hyphens are not permitted in function names.

if (-e "C:\\Data\\Logs") { print "it exists!\n"; } if (-d "C:\\Data\\Logs") { print "it is a directory!\n"; } if (-r "C:\\Data\\Logs") { print "it is readable!\n"; } if (-w "C:\\Data\\Logs") { print "it is writeable!\n"; }

See the documentation for -X in perlfunc.

perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'


Comment on Re: how to know if a path exists or not
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (15)
As of 2014-07-24 19:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (166 votes), past polls