cooldude832 Posted July 8, 2007 Share Posted July 8, 2007 The title says it all i guess Link to comment https://forums.phpfreaks.com/topic/58992-solved-how-can-i-return-the-number-of-files-in-a-folder/ Share on other sites More sharing options...
teng84 Posted July 8, 2007 Share Posted July 8, 2007 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); Link to comment https://forums.phpfreaks.com/topic/58992-solved-how-can-i-return-the-number-of-files-in-a-folder/#findComment-292760 Share on other sites More sharing options...
AndyB Posted July 8, 2007 Share Posted July 8, 2007 Slightly shorter ... put this in the target folder <?php $num = glob("*.*"); echo count($num). " files"; ?> Link to comment https://forums.phpfreaks.com/topic/58992-solved-how-can-i-return-the-number-of-files-in-a-folder/#findComment-292761 Share on other sites More sharing options...
cooldude832 Posted July 8, 2007 Author Share Posted July 8, 2007 glob I always forget about you.... Link to comment https://forums.phpfreaks.com/topic/58992-solved-how-can-i-return-the-number-of-files-in-a-folder/#findComment-292765 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.