Home > Archive > PHP Programming > June 2005 > is_dir problem (newbie)...
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
is_dir problem (newbie)...
|
|
| Bruce Spainhower 2005-06-08, 3:57 pm |
| Using the following code...
$pathname = ".";
$dh = opendir($pathname);
while (($dirname = readdir($dh)) !== false) {
if (is_dir($dirname)) $dirs[] = $dirname;
}
closedir($dh);
echo "<pre>\n";
print_r($dirs);
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:
Array
(
[0] => .
[1] => ..
)
even though there are directories within those directories. I've tried
this on both Windows and Linux boxes - same results. Suggestions?
Thanks,
- Bruce
| |
| Anonymous 2005-06-08, 3:57 pm |
| Bruce Spainhower wrote:
>
> Using the following code...
Your code works fine here. Latest PHP 4.x and apache 2 running on XP.
Bye!
| |
| Andy Hassall 2005-06-08, 8:56 pm |
| On Wed, 08 Jun 2005 12:10:17 -0500, Bruce Spainhower
<bruce@focalpointsystems.com> wrote:
>Using the following code...
>
> $pathname = ".";
>
> $dh = opendir($pathname);
> while (($dirname = readdir($dh)) !== false) {
> if (is_dir($dirname)) $dirs[] = $dirname;
> }
> closedir($dh);
>
> echo "<pre>\n";
> print_r($dirs);
> 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:
>
>Array
>(
> [0] => .
> [1] => ..
> )
>
>even though there are directories within those directories. I've tried
>this on both Windows and Linux boxes - same results. Suggestions?
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;
--
Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
| |
| Bruce Spainhower 2005-06-08, 8:56 pm |
| 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
language.
- Bruce
Andy Hassall <andy@andyh.co.uk> wrote in
news:tqfea1p074cpiom0u17i8edf9ier0kgi8n@
4ax.com:
> On Wed, 08 Jun 2005 12:10:17 -0500, Bruce Spainhower
><bruce@focalpointsystems.com> wrote:
>
>
> 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;
>
|
|
|
|
|