To See if a Directory Exists in Perl
To see
if a directory already exists in Perl:
if (-d "../citydata") {
print "There is a directory named citydata!";
}
else {
print "There is a no such directory.";
}
-We use -d to check for the directory.
-We enclose the path to the directory in quotation marks. In this instance, one directory up is where we want to look for our directory citydata, so we use ../
-We print the results of our checking.
Copy and Paste Perl Code:
#!/usr/bin/perl
print "Content-type:text/html\n\n";
if (-d "../citydata") {
print "There is a directory named citydata!";
}
else {
print "There is a no such directory.";
}
exit;
Resources:
Check for Existing File in Perl
If, Elsif, and Else in Perl
Click HERE to comment or discuss at iLoveTheCode GOOGLE Group
HTML Gary B. Shelly, Th... | | |
| | | |
| | | |