Calculating number of code lines in your project – Batch file

Hi!

Ever interested in counting the total number of code lines in your project? Well, if it is one or two files there is no problem, but if the project is large and with many subfolders, and with other files appart from code…

I’ve found a solution using bacth in Windows (possibly in Linux is easier…).


:: This batch file reads cpp and h files recursively and counts number of lines
echo off
setlocal
echo "--------------------------------"
echo "Reading number of code lines"
echo "--------------------------------"
echo off
set /a totalNumLines = 0
SETLOCAL ENABLEDELAYEDEXPANSION
for /r %%f in (*.cpp *.h ) do (
for /f %%C in ('Find /V /C "" ^< %%f') do set Count=%%C
echo !Count! lines in %%f
set /a totalNumLines+=!Count!
)
echo Total Number of Code Lines: %totalNumLines%

In our case, we found our library Viulib (http://www.vicomtech.es/viulib/) is now about 180k code lines and growing!
Hope you find it useful!

This entry was posted in Other stuff... and tagged . Bookmark the permalink.

One Response to Calculating number of code lines in your project – Batch file

  1. AitorMoreno says:

    I’ve been using cloc for years, and it is very useful and informative
    http://cloc.sourceforge.net/

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s