views:

26

answers:

2

Here is my PHP code:

<?php

// Enumerate the directories in styles
$styles_dir = 'styles/';

if($handle = opendir($styles_dir))
{
    while(FALSE !== ($file = readdir($handle)))
    {
        echo $file . '(' . is_dir($file) . ')<br>';
    }
}
?>

Here are the directories in styles:

And here is the output:

.(1)
..(1)
forest()
industrial()

Why aren't forest and industrial directories?

+1  A: 

The path for is_dir is relative to the base file, so you really need to do a test like

is_dir($styles_dir . '/' . $file)

Note that this is masked for the . and .. "directories" as these exist everywhere.

Mark E
Oh yeah.... *(slams head against wall)*
George Edison
+1  A: 

You need to prefix the directory name to the file name as is_dir works relative to the current directory.

Change

echo $file . '(' . is_dir($file) . ')<br>';

to

echo $file . '(' . is_dir("$styles_dir/$file") . ')<br>';

Alternatively you can change the directory to $styles_dir using chdir and then your current code will work.

codaddict