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 ""
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.
Bill PrewCommented:
Do you just want one grand total, or a total per file?

Do you want to include blank lines in the count?

Steve KnightIT ConsultancyCommented:
Thanks, hope that helped then

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.