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?

  • 1
    [Do you know a similar program for wc (unix word count command) on Windows?][1] [1]: stackoverflow.com/questions/247234/… – sinping Oct 12 '11 at 17:50
  • I'm familiar with wc, I wish there was a W7 equivellant. – quillbreaker Oct 12 '11 at 18:17
  • @ (quillbreaker) There is. The entire Linux/Unix command line toolkit is available for ALL windows based platforms. gnuwin32.sourceforge.net – shawty Apr 20 '18 at 18:51

powershell is an option.

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

Lines Words Characters Property
----- ----- ---------- --------
| improve this answer | |
  • 1
    please provide evidence and alternate solution if above is incorrect. I will then delete/correct my answer. – maweeras May 6 '16 at 6:56
  • 3
    While your answer is helpful and accepted by the OP, it doesn't correctly answer OP's question. The problem is in the first command in your solution - dir -Recurse *.txt will only process directories whose names match *.txt, while outputting all the files that it finds in those directories and their subtrees. But the OP wanted to process all directories while outputting only the files that match *.txt. To do that, you would use dir -Recurse -Include *.txt. – Cinnam May 26 '16 at 2:19
  • 1
    This is incorrect, the windows help on Get-ChildItem (which dir is an alias of) states that Get-ChildItem –Path "*.txt" -Recurse is all that is needed to get "all of the .txt files in the current directory and its subdirectories." link: technet.microsoft.com/library/hh849800.aspx – Andrew Leap Aug 27 '16 at 3:52
  • @AndrewLeap I just tested it again - on Win8 with PowerShell 4.0 it works as you say. However on Win7 with PowerShell 2.0 it has the problem I described. dir -Recurse -Include *.txt seems to have the desired results on both of these versions. – Cinnam Sep 1 '16 at 17:08
  • How would someone use this to check in BOTH *.txt AND *.java (combined total)? – Jeremy Moritz Oct 3 '17 at 15:09

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
| improve this answer | |

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"
| improve this answer | |

I'm using the free and lite tool http://www.locmetrics.com

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.