opendir() with Mac OS X
I am doing a recursive directory traversal which I originally wrote for Win XP but had to port it over to the Mac. It's not working like it did on the PC. The problem seems to be with the Opendir() function.
<?php
function recursedir($BASEDIR)
{
$hndl=opendir($BASEDIR);
echo \"recursedir : hndl = $hndl<br>\";
while($file=readdir($hndl))
{
if ($file=='.' || $file=='..') continue;
$completepath=\"$BASEDIR/$file\";
if (is_dir($completepath))
{
# its a dir, recurse.
print \"<font color=\\"#FF0000\\"> DIR: $BASEDIR/$file</font><br>\n\";
recursedir($BASEDIR.'/'.$file);
}
else
{
# its a file.
print \"FILE: $BASEDIR/$file<br>\n\";
$FN = $BASEDIR.\"/\".$file;
ReadThisFile($FN);
}
}
} //Recurse Dir
?>
When I echo the opendir handle on the PC I get "recursedir : hndl = Resource id # N" (N is a number), but when I do the same call on the Mac, I just get "recursedir : hndl = " and then it stops and won't recurse. Any ideas? Thanks in advance.
- sharyn
sharyn posted this at 18:09 — 19th August 2004.
They have: 18 posts
Joined: Aug 2004
ok, nevermind, the code actually works. It turns out, I was not giving it the entire path, I just started from the path the app was at (ie /Inetpub/wwwroot - or whatever the Mac path is).
- sharyn
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.