Re: Results from is_dir() not consistent with documentation (?)
| From: | Jason B. Standing | Date: | Thu, 01 May 2003 05:40:56 +0000 |
| Subject: | Re: Results from is_dir() not consistent with documentation (?) | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-145902@lists.php.net to get a copy of this message | ||
> Looks like the stat system over smb is not 100% reliable.
> Maybe on the null ones you could try changing to it as if it was a
> directory and if that fails then it is not a directory..
OK, here's the code I wound up with :
Importantly, I needed to have
error_reporting(1);
at the top of the script, otherwise all those warnings would have driven me
crazy :)
The recursive function thereafter was:
function traverseDir($item_to_test, $level, $file_path) {
$level = $level + 1;
if (strcmp($item_to_test, ".") == 0) {
$fullpath = <some path>;
}
else {
$fullpath = $file_path . "/" . $item_to_test;
}
if((boolean)opendir($fullpath) == 1) {
if ($handle = opendir($fullpath)) {
while (false !== ($file = readdir($handle))) {
//exclude the . and .. files
if ($file != "." && $file != "..") {
traverseDir($file, $level, $fullpath);
}
}
}
}
else {
echo str_repeat(" ", $level * 2) . $file_path .
"/" .
$item_to_test . "<br>\n";
}
}
All that $level really was for was to indent the echo during the script
output, but it servers as a kind of counter to find how many levels deep
your directory structure goes...
Thanks everyone for your help :)
Jason =)