Question : Batch file to count number of lines

I am looking for a method that will take a directory as an input and count the number of lines in each individual file within that directory, and its sub-directories.
I assume this could be done via a batch file or something similar.


The reason for the requirement is that I want to find out how many lines of code I have in a project.  I use Clarion, and there doesn't seem to be a specific method.   The above idea wouldn't be accurate as it doesn't take into account comments etc, but it will do for now.
Also, if someone knows of a better place to find an answer to this, please point me in the right direction.

Answer : Batch file to count number of lines

If that's EXACTLY what you have, then you have a space in there that should be.

for /f "tokens=1*" %a in ('for /r %c in ^("C:\Devapps\Projects\code\"^) do wc -l *.clw') do @echo %a, %b >>c:\linecounts.csv

In testing this, I had:
for /f "tokens=1*" %a in ('for /r %c in ^(c:\temp\^) do wc -l *.txt') do @echo %a, %b
and it worked fine... hmmm... very odd... I do see your version is otherwise the same... where is wc located (I put it in a folder that's in my path).

Well, another possibility - as I did kind of throw a curve ball there (I switched the for command from a /f to a /r (/r walks a directory structure; /f processes with more of a list format.

No reason I can see why it wouldn't be working, but try this instead (going back to the method of my first offering):

for /f "tokens=1*" %b in ('for /f "tokens=*" %a in ^('dir /b /s /a-d  C:\Devapps\Projects\code\*.clw'^) do @wc -l "%a"') do @echo %b,%c>>c:\linecounts.csv
Random Solutions  
 
programming4us programming4us