To see if a file exists before using it, we can use:
if (-e "filename.cgi") { #proceed with your code }
But how to indentify a directory exists or not?