Zend - The PHP Company




Files and Directories

Add Code


disk usage  

Type: code fragment
Added by: danielsan
Entered: 03/02/2002
Last modified: 02/12/2001
Rating: - (fewer than 3 votes)
Views: 9005
Returns disk usage in bytes of directory $d. Limit depth level with $depth.


<?php
/*
 *  Returns disk usage in bytes of directory $d. Limit depth level with $depth.
 *  Updates, documentation and examples: http://daniel.lorch.cc/projects/disk_usage/
 *
 *  Revision: 1.00
 */

function disk_usage($d$depth NULL) {
  if(
is_file($d))
    return 
filesize($d);

  if(isset(
$depth) && $depth 0)
    return 
0;
    
  if(
$d[strlen($d)-1] != '\' || $d[strlen($d)-1] != '/')
    $d .= '
/';
    
  $dh=@opendir($d);
  if(!$dh)
    return 0;

  while($e = readdir($dh))
    if($e != '
.' && $e != '..')
      $usage += disk_usage($d.$e, isset($depth) ? $depth - 1 : NULL);

  closedir($dh);

  return $usage;
}
?>


Usage Example


See the example


Rate This Script





Search



This Category All Categories