Verzeichnisgröße

Dateigrößen innerhalb eines Verzeichnis summieren
Beispiel ausführen
<?php


  
function ByteSize($bytes
   {

    if (!
is_int($bytes) || $bytes 0){
        return 
false;
    }

    
$map = array(
     
'GB' => array(10737418241),
     
'MB' => array(10485762),
     
'KB' => array(10242),
     
'Bytes' => array(10),
    );
   
    foreach(
$map as $k => $v){
        if (
$bytes >= $v[0]){
            break;
        }
    }
    
    
$f number_format($bytes $v[0], $v[1],',','.');

    if (
$bytes 2){
        
$k 'Byte';
    }
    
    return 
sprintf ('%s %s',$f$k);
  }

function 
dirinfo($path)
{
    
$tmp glob_recursive($path);
    
$qty_all count($tmp);
    
$tmp array_filter($tmp'is_file');
    
$qty_file count($tmp);
    
$qty_dir $qty_all-$qty_file;
    
$s array_map('filesize'$tmp);
    
$size ByteSizearray_sum($s) );

    
$arr = array(
        
0            => $qty_file,
        
1             => $qty_dir,
        
2             => $size,

        
'files'       => $qty_file,
        
'directories' => $qty_dir,
        
'size'           => $size,
    );

    return 
$arr;
}  
  
function 
glob_recursive($sDir$sPattern='*'$nFlags NULL)
{
  
$sDir escapeshellcmd($sDir);

  
// Get the list of all matching files currently in the
  // directory.

  
$aFiles glob("$sDir/$sPattern"$nFlags);

  
// Then get a list of all directories in this directory, and
  // run ourselves on the resulting array.  This is the
  // recursion step, which will not execute if there are no
  // directories.

  
foreach (glob("$sDir/*"GLOB_ONLYDIR) as $sSubDir)
  {
   
$aSubFiles glob_recursive($sSubDir$sPattern$nFlags);
   
$aFiles array_merge($aFiles$aSubFiles);
  }

  
// The array we return contains the files we found, and the
  // files all of our children found.

  
return $aFiles;
}

echo 
'<pre>';
var_dump(dirinfo(dirname(__FILE__)));
echo 
'</pre>';

?>

Benutzte Funktionen


Hinweise zum DatenschutzImpressum © 2005-2008 S. Eickhoff