note 24556 deleted from ref.dir by sniper
| From: | sniper@php.net | Date: | Thu, 15 Dec 2005 23:59:45 +0000 |
| Subject: | note 24556 deleted from ref.dir by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-100249@lists.php.net to get a copy of this message | ||
Note Submitter: admin[ at T]networkessence dot net
----
This script will count lines of code that do not begin with // or are not blank space. It's
very approximate because it will include /* */ comments and will also include lines that start with
blank space and then //. It's a start though (it's recursive, so don't use this with
a directory structure that includes symbolic links). This will recursively count all the lines of
files that end with .php. You can change .php to whatever, and also change the guidelines as to
whether a line qualifies as a comment or not (look around the !="//" part)
$i=0;
function getDirList ($dirName) {
global $i;
$d = dir($dirName);
while($entry = $d->read()) {
if ($entry != "." && $entry != "..") {
if (is_dir($dirName."/".$entry)) {
getDirList($dirName."/".$entry);
} else if(substr($entry, -4)=='.php') {
if($read_file = file($dirName.'/'.$entry))
foreach($read_file as $line)
if(($line!="\n") &&
(substr($line, 0, 2)!="//"))
$i++;
echo $dirName."/".$entry."\n";
}
}
}
$d->close();
}
getDirList("./path/to/files");
echo $i;