How to count all the lines of code in a directory recursively on Windows?

On a Windows 7 machine, I'd like a quick way to determine the number of lines in all of the files in a directory tree, for files of a given extension. Is there any good out of the box way to do this?


You can use Measure-Object in powershell like this:

PS D:\temp> dir -Recurse *.txt | Get-Content | Measure-Object -Line

Which will return the following:

Lines Words Characters Property
----- ----- ---------- --------
  168

To expand on maweeras answer above (sorry not enough rep to comment), you can search for multiple file extensions by passing a comma-delimited array to -Include.

So for example:

dir -Recurse -Include *.ts,*.tsx -Exclude *node_modules* | Get-Content | Measure-Object -Line

The following works in cmd:

for %f in (*.TXT) do find /v /c "" "%f"

Or in a [.bat]:

for %%f in (*.TXT) do find /v /c "" "%%f"