Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Test the existance of a directory

by gitarwmn (Beadle)
on Jun 18, 2004 at 16:15 UTC ( [id://367984]=perlquestion: print w/replies, xml ) Need Help??

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

How do I test for the existance of a directory? Thanks Thanks everyone.

Replies are listed 'Best First'.
Re: Test the existance of a directory
by bassplayer (Monsignor) on Jun 18, 2004 at 16:25 UTC
    Assuming you mean in Perl, you should check into the File Test Operators, specifically -d.

    bassplayer

Re: Test the existance of a directory
by fluxion (Monk) on Jun 18, 2004 at 16:25 UTC
    if (-d $dir) { ... }

    Roses are red, violets are blue. All my base, are belong to you.
Re: Test the existance of a directory
by Enlil (Parson) on Jun 18, 2004 at 16:25 UTC
      ..oftopic..

      is -enlil a new file test operator? :p
      or is nlil considered a bareword and does the code actually mean -e "nlil"?
      In both cases, what will be the result of it?
Re: Test the existance of a directory (open it)
by grinder (Bishop) on Jun 19, 2004 at 06:44 UTC

    Sometimes the best way to test for the existence of the directory is to go ahead and see if you can open it. If you want to know if it exists, you may want to look at something in it, so just go ahead and see if you can. It's the ultimate test.

    #! /usr/bin/perl -w use strict; for my $dir( @ARGV ) { if( opendir( D, $dir )) { print "$dir: yup\n"; closedir D; } else { print "$dir: nope\n"; } }

    - another intruder with the mooring of the heat of the Perl

Log In?
Username:
Password:

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

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

    No recent polls found