Well, you're not checking for files/directories. It will also pick up hidden files and directories, like . and ..
Here's something I put together, wondering how many files and lines of code I have in my multiple www directories. You may be able to use some of this to get what you need....
function get_files($dir, $res=array()) {
if($id = opendir($dir)) {
while(false !== ($arch = readdir($id))){
if($arch != "." && $arch != "..") {
if(is_dir($dir.$arch)) {
$res = get_files($dir.$arch."/", $res);
}
else {
$res[] = $dir.$arch;
}
}
}
closedir($id);
}
return $res;
}
$lines = 0;
$tfile = 0;
$dirs = array("/var/www/", "/var/cronscripts/", "/var/central/", "/usr/local/lib/php/inc/");
foreach($dirs as $d) {
$files = get_files($d);
foreach($files as $file) {
$tfile++;
$lines += trim(ereg_replace("[^0-9]+$","",(`wc -l $file`)));
}
}
echo "\n\nTOTAL LINES: ".number_format($lines)."\n\nTOTAL FILES: ".$tfile."\n\n";