OK so i have this code that counts the number of times a certain phrase is repeated in a folder full of text files but i’m trying to figure out how to display a total after echoing all of them
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
Colin Gardner is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Capture the counter with another for /f
loop and add them up with set /a
.
Another for
around spares you repeating code segments (easily to expand for more players).
@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/
)