note 24556 added to ref.dir
| From: | admin@php.net | Date: | Wed, 21 Aug 2002 09:41:33 +0000 |
| Subject: | note 24556 added to ref.dir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-35302@lists.php.net to get a copy of this message | ||
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;
--
http://www.php.net/manual/en/ref.dir.php
http://master.php.net/manage/user-notes.php?action=edit+24556
http://master.php.net/manage/user-notes.php?action=delete+24556
http://master.php.net/manage/user-notes.php?action=reject+24556