note 34144 added to ref.filesystem

From: Date: Thu, 17 Jul 2003 03:25:47 +0000
Subject: note 34144 added to ref.filesystem
Groups: php.notes 
Request: Send a blank email to php-notes+get-52244@lists.php.net to get a copy of this message
I needed a function to find disk usage for a directory and its subs, so here it is. It's kinda like the Unix du program, except it returns the usage in bytes, not blocks. function du($location) { if (!$location or !is_dir($location)) { return 0; } $total = 0; $all = opendir($location); while ($file = readdir($all)) { if (is_dir($location.'/'.$file) and $file <> ".." and $file <> ".") { $total += du($location.'/'.$file); unset($file); } elseif (!is_dir($location.'/'.$file)) { $stats = stat($location.'/'.$file); $total += $stats['size']; unset($file); } } closedir($all); unset($all); return $total; } print du('/some/directory'); ---- Manual Page -- http://www.php.net/manual/en/ref.filesystem.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+34144 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+34144&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+34144&report=yes

« previous php.notes (#52244) next »