is_dir problem (newbie)...

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

Using the following code...

  $pathname = ".";
  $dh = opendir($pathname);
  while (($dirname = readdir($dh)) !== false) {
    if (is_dir($dirname)) $dirs[] = $dirname;
  echo "<pre>\n";
  echo "</pre>\n";

....I get a correct listing of directories under the current directory.  For
any other $pathname, (e.g. "./MySub/", "/Temp", "AnotherSub") the only
thing returned is:

    [0] => .
    [1] => ..

even though there are directories within those directories.  I've tried
this on both Windows and Linux boxes - same results.  Suggestions?


 - Bruce

Re: is_dir problem (newbie)...

On Wed, 08 Jun 2005 12:10:17 -0500, Bruce Spainhower

Quoted text here. Click to load it

 readdir() produces filenames _relative to the directory it's scanning_.

 Your is_dir() calls will therefore only work when $pathname is the current
directory. You likely want something more like:

    if (is_dir("$pathname/$dirname")) $dirs[] = $dirname;

< Space: disk usage analysis tool

Re: is_dir problem (newbie)...

Thanks Andy!  That did the trick.  Makes perfect sense.  It's one of those
things that hides right in front your nose when switching to a new

 - Bruce

Quoted text here. Click to load it

Re: is_dir problem (newbie)...

Bruce Spainhower wrote:
Quoted text here. Click to load it

Your code works fine here. Latest PHP 4.x and Apache 2 running on XP.


Site Timeline