"K.L. Hayes" wrote:
> 
> Hello All,

Hello,

> I've found lot's of info on how to check if a file exists but nothing
> about checking if a directory exists. I've posted the relevant code
> below along with 3 variations of how I "think" it might work. If
> somebody could point to the one that is "correct" or knows of a better
> way I'd appreciate the help. Thank you.

No reason to "think" about it.  Read the perlfunc documentation and
write a small program to test it.

$ perl -le'
if (-f $ARGV[0]) {print "file"} else {print "NOT a file"}
if (-d _) {print "directory"} else {print "NOT a directory"}
if (-r _) {print "readable"} else {print "NOT readable"}
if (-w _) {print "writable"} else {print "NOT writable"}
if (-x _) {print "executable"} else {print "NOT executable"}
if (-e _) {print "exists"} else {print "NOT exists"}
if (-s _) {print "size"} else {print "NO size"}
' test.txt
file
NOT a directory
readable
writable
NOT executable
exists
size

$ perl -le'
if (-f $ARGV[0]) {print "file"} else {print "NOT a file"}
if (-d _) {print "directory"} else {print "NOT a directory"}
if (-r _) {print "readable"} else {print "NOT readable"}
if (-w _) {print "writable"} else {print "NOT writable"}
if (-x _) {print "executable"} else {print "NOT executable"}
if (-e _) {print "exists"} else {print "NOT exists"}
if (-s _) {print "size"} else {print "NO size"}
' bin     
NOT a file
directory
readable
writable
executable
exists
size


perldoc -f -X


> use constant USER_PATH => '/home/~client/htdocs/clients/';
> $path = USER_PATH . $personal_key;
> 
> ## Is This Correct? ##
> if (-e "$path") {
>         &get_on_with_it }
>         else { &errorMsg }
> 
> ## Or This? ##
> opendir(CLIENT, "$path") or die " &errorMsg ";
> closedir(CLIENT);
> &get_on_with_it
> 
> ## Or Is It This? ##
> if (-d $path) {
>         &get_on_with_it }
>         else { &errorMsg }


The Perl motto is "There Is More Than One Way To Do It"  :-)



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to