[SOLVED] opendir() with Mac OSX

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
sharyn
Forum Commoner
Posts: 33
Joined: Tue Jun 15, 2004 6:39 pm
Location: So Cal

[SOLVED] opendir() with Mac OSX

Post by sharyn »

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.

Code: Select all

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
Last edited by sharyn on Thu Aug 19, 2004 12:57 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

try using DIRECTORY_SEPERATOR (a constant) instead of / ... since Mac's don't use / for directory seperation...
User avatar
sharyn
Forum Commoner
Posts: 33
Joined: Tue Jun 15, 2004 6:39 pm
Location: So Cal

Post by sharyn »

Feyd,

I am using OSX which is unix based, so while the directory separator used to be a ":", it's now using "/"s. But I fixed the problem. It turns out I was not passing it the entire path, just the path from where I was starting from (ie. inetpub/wwwroot - or whatever the case is for Macs.

So the code actually works, I just had to feed it the right input. heh heh heh :oops:

I appreciate your help though.

- sharyn
Post Reply