<?php
/*************************************************
dirsizer.php - a simple utility to list the total sizes of files in a folder, and the number of lines in .htm and .php files
home page: www.samscripts.com/scripts/dirsizer
support: support.samscripts.com/index.php
licence: freeware
author: Sam Yapp
date: 8th September 2002
documentation and examples at www.samscripts.com
usage:
include("dirsizer.php");
$d = new dirsizer("path/to/scan");
*************************************************/
class dirsizer{
function dirsizer($path){
$this->dirs = array();
$this->totalsize = 0;
$this->totallines = 0;
$this->getdirectoryinfo($path);
echo "<pre>";
print_r($this->dirs);
echo "</pre>";
echo "Total Lines: ".$this->totallines."<br>Total Size: ".$this->totalsize."<br><br>";
}
function getdirectoryinfo($path){
$this->dirs[$path]["files"] = 0;
$this->dirs[$path]["folders"] = 0;
$this->dirs[$path]["filesizes"] = 0;
$this->dirs[$path]["totallines"] = 0;
$d = dir($path);
while( false !== ($entry = $d->read())){
if( $entry != "." && $entry != ".." ){
$entrypath = $path."/".$entry;
if( is_file($entrypath) ){
if( preg_match("~\.(php|htm)$~i", $entry)){
$this->dirs[$path]["files"]++;
$this->dirs[$path]["filesizes"] += filesize($entrypath);
$f = file($entrypath);
$this->dirs[$path]["totallines"] += count($f);
}
}else{
$this->dirs[$path]["folders"]++;
$this->getdirectoryinfo($entrypath);
}
}
}
$this->totalsize += $this->dirs[$path]["filesizes"];
$this->totallines += $this->dirs[$path]["totallines"];
$d->close();
}
}
?>