Jump to content

[SOLVED] How can i return the number of files in a folder?


cooldude832

Recommended Posts

function dirTree($dir) {

    $d = dir($dir);

    while (false !== ($entry = $d->read())) {

        if($entry != '.' && $entry != '..' && is_dir($dir.$entry))

            $arDir[$entry] = dirTree($dir.$entry.'/');

    }

    $d->close();

    return $arDir;

}

 

function printTree($array, $level=0) {

    foreach($array as $key => $value) {

        echo "<div class='dir' style='width: ".($level*20)."px;'> </div>".$key."<br/>\n";

        if(is_array($value))

            printTree($value, $level+1);

    }

}

 

Usage is as simple as this:

$dir = "<any directory you like>";

$arDirTree = dirTree($dir);

printTree($arDirTree);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.