Its the same msg when the dir searched is found.
while ( $dir_name = readdir($dir) ) {
if ( $dir_name == "foo" ) {
print "i found your directory!";
}
else { print "Direc not found"; }
}
That's your loop. The If-else statement is inside the loop. So everytime the loop iterates, and it's not "foo", then it's going to print "Direc not found". Consider this:
$i = 0;
while ($i < 5) {
print "Direc not found";
$i++;
}
That'll print "Direc not found" 5 times. And that's what you're doing in your loop, except that your print statement is inside an if-else statement.
To correct it, do something like this:
$found = false;
while ( $dir_name = readdir($dir) ) {
if ( $dir_name == "foo" ) {
$found = true;
}
}
if ($found)
print "Direc found";
} else {
print "Direc not found";
}
Diego