Count Lines of Code in Directory

I want to count all of the lines within all files and directories starting here c:\project1

Is there a way to do this with the cmd prompt? Or do I need to install a tool?
LVL 12
Nathan RileyFounderAsked:
Who is Participating?
 
Steve KnightIT ConsultancyCommented:
Or if you want count of lines using just batch then:

find /c /v "" *.txt

Shows you total lines in each file in that dir.

@echo off
cd /d c:\project1
for /f %%a in ('type *.txt ^| find /c /v ""') do set lines=%%a
echo %lines%

Shows you total no. of lines in all files

Or in all subdirs too:

(for /r %f in (*.txt) do type "%~f") | find /c /v ""

or in batch:

@echo off
cd /d c:\project1
(for /r %%f in (*.txt) do type "%%~f") ^| find /c /v ""
0
 
NVITCommented:
One solution: Use CLOC.

cloc counts blank lines, comment lines, and physical lines of source code in many programming languages. Given two versions of a code base, cloc can compute differences in blank, comment, and source lines.

http://cloc.sourceforge.net/
http://stackoverflow.com/questions/1358540/how-to-count-all-the-lines-of-code-in-a-directory-recursively
0
 
Bill PrewCommented:
Do you just want one grand total, or a total per file?

Do you want to include blank lines in the count?

~bp
0
 
Steve KnightIT ConsultancyCommented:
Thanks, hope that helped then

Steve
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.