Check the existence of the directory
Use the file test operator "-d" to check if a directory exists .
-d $file
Returns a true value if the directory exists, a false value if it does not exist.
This is an example to check the existence of a directory using the file operator -d.
use strict; use warnings; # Check for the existence of the directory. # -d directory name print "1: Check the existence of the directory. -D\n"; my $dir = 'd'; if (-d $dir) { print "'$dir' exists.\n"; } else {print "'$dir' does not exist.\n"}