我有这段代码:
@echo off
:CountLines
setlocal
set /a totalNumLines = 0
for /r %1 %%F in (*.txt) 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
这会计算文件中的所有行,并为我提供总行数。但是,我需要它为每个文件提供文件名和行,而不是总数。
所需的输出有点像这样:
FILEA.txt 1200
FILEB.txt 300
FILEC.txt 10
答案 0 :(得分:1)
你的答案没有输出文件名:
Array (
[2001] => 5
[2002] => 7
[2003] => 7 ...
答案 1 :(得分:0)
经过大量的试验和错误,我自己找到了答案:
@echo off
:CountLines
setlocal
set /a totalNumLines = 0
for /r %1 %%F in (*.txt) do (
for /f %%N in ('find /v /c "" ^<"%%F"') do echo %%N >>log.txt
)