Posted by Bruce Spainhower on 06/09/05 00:51
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:
>
>>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;
>
[Back to original message]
|