Listing directory

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

I used following code to scan & list directory contents (including all
subdirectories). It turns out that subdirectories are NOT recognized as
directories when the function is called in a recursive way.
In other words when function scans a subdirectory no directories inside are
recognised as directories therefore it cannot scan ti's contents.

$directory = "/www/prawnik/";
function list_dir($dir) {
if ($handle = opendir($dir)) {
        static $indent = 2;
        echo "indent=$indent<br>";
        echo "dir=$dir<br>";
        while (false !== ($file = readdir($handle))) {
                if ($file=="." || $file =="..") continue;
                if (is_dir($file)=='dir') {
                        for ($index=1; $index<=$indent; $index++) {
                                echo "&nbsp&nbsp";
                        echo "<B>$file:".filetype($dir)."</B><br>";
                        $newdir = $dir.$file."/";
                        list_dir ($newdir);
                } else echo "$indent:$file<br>";

list_dir ($directory);

Site Timeline