Log in

View Full Version : Count Code Lines


joeboo
01-29-2006, 08:48 PM
Do any of you guys know of a program that can count the number of lines (PHP lines) of files? Like, selecting a folder where PHP files are stored and having it count all the lines of every file.

BamaStangGuy
01-29-2006, 08:55 PM
Filburt may know since he has a huge project he is working on

sabret00the
01-30-2006, 09:41 AM
Do any of you guys know of a program that can count the number of lines (PHP lines) of files? Like, selecting a folder where PHP files are stored and having it count all the lines of every file.

you could write a function to do it in php

Lea Verou
03-17-2006, 10:52 PM
I also need this...

(and I'm too lazy to write it in php :p)

filburt1
03-18-2006, 05:08 PM
Filburt may know since he has a huge project he is working on
I just wrote my own script that recursively enters each chosen directory and counts each file's lines. Not very good but it works.

Lea Verou
03-18-2006, 05:35 PM
will you share? :)

filburt1
03-18-2006, 09:41 PM
<?php
$count = 0;

$delim = strstr(PHP_OS, "WIN") ? "\\" : "/";

ob_implicit_flush();

$filenames = array();

function count_lines($path)
{
global $delim, $count, $filenames;

if ($dir = @opendir($path))
{
while (($element = readdir($dir))!== false)
{
if (is_dir($path . $delim . $element) && $element != "." && $element != "..")
{
count_lines($path . $delim . $element);
}
else if ($element != "." && $element != ".." and
strpos($element, "vbms") !== false
and !in_array($element, $filenames))
{
$filenames[] = $element;
$linecount = sizeof(file($path . $delim . $element));
echo $element . " (<em>$linecount lines</em>)<br />";
$count += $linecount;
}
}
closedir($dir);
}
}

$path = "some directory";
count_lines($path);
$path = "some other directory";
count_lines($path);

echo "<strong>$count</strong> total lines";
?>
Will need significant changes to work for your setup.

Lea Verou
03-18-2006, 09:43 PM
Thanks!