How to find out if a directory exists in Perl?

To find out if a file exists before using it, we can use:

if (-e "filename.cgi") { #proceed with your code } 

But how to determine the directory exists or not?

+47
directory file-io perl
Dec 20 2018-10-12T00:
source share
1 answer

Use -d ( full list of file tests )

 if (-d "cgi-bin") { # directory called cgi-bin exists } elsif (-e "cgi-bin") { # cgi-bin exists but is not a directory } else { # nothing called cgi-bin exists } 

As a side note, -e does not distinguish between files and directories. To check if anything exists and is a simple file, use -f .

+85
Dec 20 '10 at 4:52
source share



All Articles