Forum Moderators: coopster

Message Too Old, No Replies

opendir() with Mac OSX

         

sharyn

12:55 am on Aug 18, 2004 (gmt 0)

10+ Year Member



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.


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

timster

12:20 pm on Aug 18, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The code looks OK. I just ran it on my PowerBook and am getting filehandles, e.g.,

recursedir : hndl = Resource id #271

Could it be a permissions problem? When I tried it on a directory that the script did not have permissions to, I got these errors:


Warning: opendir(/Users/guy/Music): failed to open dir: Permission denied in /Users/cciu/bin/recu.php on line 9
recursedir : hndl = <br>
Warning: readdir(): supplied argument is not a valid Directory resource in /Users/cciu/bin/recu.php on line 11

timster

12:27 pm on Aug 18, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



By the way, here's how I got the script to report the errors:

Use the Terminal app (inside the /Applications/Utilities directory) to run the script from the command line (with

php scriptname.php
).

sharyn

6:05 pm on Aug 19, 2004 (gmt 0)

10+ Year Member



Thanks Timster. I'm an idiot... the code actually works for me too. 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