note 52360 added to function.filesize

From: Date: Thu, 28 Apr 2005 16:51:31 +0000
Subject: note 52360 added to function.filesize
Groups: php.notes 
Request: Send a blank email to php-notes+get-88704@lists.php.net to get a copy of this message
here a small function to retrieve a folder's size recursive :-) I don't know if there is no function that retrieves a folder size or if I was just to dumb to find it :-) hint: call the function with $output=true if you want to have also a status message where the function read that stuff .. usually you don't need that <?php function get_folder_size($target, $output=false) { $sourcedir = opendir($target); while(false !== ($filename = readdir($sourcedir))) { if($output) { echo "Processing: ".$target."/".$filename."<br>"; } if($filename != "." && $filename != "..") { if(is_dir($target."/".$filename)) { // recurse subdirectory; call of function recursive $totalsize += get_folder_size($target."/".$filename, $exceptions); } else if(is_file($target."/".$filename)) { $totalsize += filesize($target."/".$filename); } } } closedir($sourcedir); return $totalsize; } $size = get_folder_size("/var/www/html", false); // $size has the value of bytes found in directory // output size in kb echo "~".(int)($size/1024)."kb"; ?> greetingz, D. ---- Manual Page -- http://www.php.net/manual/en/function.filesize.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+52360 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+52360&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+52360&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+52360&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+52360&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+52360&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+52360&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#88704) next »