Vivid Lust Posted July 18, 2008 Share Posted July 18, 2008 I know you cant count files in a given directory, how can you find the size of a given directory ??? Thanks in advanced.! Link to comment https://forums.phpfreaks.com/topic/115467-get-size-of-a-given-directory/ Share on other sites More sharing options...
aseaofflames Posted July 18, 2008 Share Posted July 18, 2008 <?php function show_dir($dir, $pos=2){ global $totalsize; $handle = @opendir($dir); while ($file = @readdir ($handle)){ if (eregi("^\.{1,2}$",$file)) continue; if(is_dir($dir.$file)){ show_dir("$dir.$file/", $pos+3); }else{ $size=filesize($dir.$file); $totalsize=$totalsize+$size; } } @closedir($handle); return($totalsize); } $size = show_dir("path/to/dir/"); //returns size in bytes. trailing slash is required. ?> I know you cant count files in a given directory yes you can. <?php function count_files($dir){ $count=0; $handle = @opendir($dir); while ($file = @readdir ($handle)){ if (eregi("^\.{1,2}$",$file)) continue; if(!is_dir($dir.$file)) { $count++; } } @closedir($handle); return($count); } $size = count_files("path/to/dir/"); //returns number of files in dir. trailing slash is required. ?> Link to comment https://forums.phpfreaks.com/topic/115467-get-size-of-a-given-directory/#findComment-593660 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.