I think I'm not quite understanding something about error handling in
PHP5. I have written some PHP code to index the contents of C drive
on a Windows machine. When it gets to certain special folders (fake
folders) it runs into errors. Directories it can not read from. I
have tried wrapping the code in a Try / Catch and the error still
comes through. What am I missing?
<?php
// Here is the code:
function indexFiles($path, $handle) {
try {
$d = dir($path);
while (false !== ($entry = $d->read())) {
if (is_dir($path . '\\' . $entry)) {
if (($entry != ".") && ($entry != "..")) {
indexFiles($path . '\\' . $entry, $handle);
}
} else {
fwrite($handle, $path . '\\' . $entry . "\n");
}
}
$d->close();
} catch (Exception $e) { }
}
$p = "C:";
$fp = fopen('M:\\data.txt', 'w+t');
indexFiles($p, $fp);
fclose($fp);
?>
I get the error specifically when the script runs into the "junction
point" C:\Documents and Settings.
Junction point is similar to a symlink but on Windows Vista
Warning: dir(C:\Documents and Settings): failed to open dir: No error
in C:\test.php on line 4
Fatal error: Call to a member function read() on a non-object in C:
\test.php on line 5
Does try / catch not work? Any good articles on what I am seeing?
Thanks,
Kelly Greer
ke*********@nospam.com
change nospam to yahoo