好的,所以我有这段代码可以计算某个短语在充满文本文件的文件夹中重复的次数,但我试图弄清楚如何在回显所有短语后显示总数
set /p player=enter player name:
if /i "%player%"=="Colinderr" (
for %%i in (*.log) do (
find /c "Colinderr was killed" %%i
)
echo /a deathcount
) else if /i "%player%"=="QuickCrash1" (
for %%i in (*.log) do (
find /c "QuickCrash1 was killed" %%i
)
)
pause
用另一个
for /f
循环捕获计数器,并用 set /a
将它们相加。for
可以让您避免重复代码段(可以轻松扩展以供更多玩家使用)。
@echo off
setlocal enabledelayedexpansion
for %%p in ("Colinderr","QuickCrash1") do (
set "sum=0"
for %%i in (*.log) do (
for /f %%j in ('type "%%i"^|find /c "%%p was killed"') do (
echo %%~ni: %%j
set /a sum+=%%j
)
)
echo total deathcount %%p: !sum!
echo/
)