Batch - count lines in the files of the current folder and subfolders

This is my script, what it does is count lines from cpp, h, hpp, cs, c files in the current folder.

What I want to do is also counted in subfolders, but it seems to me that I cannot do this.

I have made several recursion attempts, but I cannot implement it in the current code.

call::CountLines Modules\Output\HTML.Tidy\
goto:eof

:CountLines
setlocal
set /a totalNumLines = 0
SETLOCAL ENABLEDELAYEDEXPANSION
for /r %%f in (%~1*.cpp %~1*.h %~1*.hpp %~1*.cs %~1*.c) do (
for /f %%C in ('Find /V /C "" ^< %%f') do set Count=%%C
set /a totalNumLines+=!Count!
)

echo Total number of cod lines for %~1: %totalNumLines% >> log.txt

Please let me know if you know a solution or a better way.

Hello,

Stephen

+4
source share
2 answers

Path information should not be in IN()use FOR /R. The root path should follow the option /R.

@echo off

:CountLines
setlocal
set /a totalNumLines = 0
for /r %1 %%F in (*.cpp *.h *.hpp *.cs *.c) do (
  for /f %%N in ('find /v /c "" ^<"%%F"') do set /a totalNumLines+=%%N
)

echo Total number of code lines for %1 = %totalNumLines% >>log.txt

, type file|find /c /v "" find /c /v "" <file . , , .

+7

:

@echo off
cd /d "%~1"
for /f "delims=" %%f in ('dir *.cpp *.h *.hpp *.cs *.c /b /s /a-d ^|find /c /v "" ') do set Count="%%f"
echo "%count%"
0

Source: https://habr.com/ru/post/1526366/


All Articles