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