这是我的脚本,它的作用是从当前文件夹中的 cpp、h、hpp、cs、c 文件中计算行数。
我想做的是也计算子文件夹,但似乎我无法做到这一点。
我做了一些递归尝试,但我无法在当前代码中实现它。
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
如果您知道解决方案或更好的方法,请告诉我。
问候,
斯特凡
最佳答案
路径信息不得在 IN()
内使用条款时 FOR /R
.根路径应遵循 /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
可以给出不同的结果。我不记得触发条件是什么,或者哪个更好。
关于batch-file - 批处理 - 计算当前文件夹和子文件夹中文件的行数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21704959/