I have a batch script but for whatever reason once a value is set in my foor loop it persists and doesn’t update. My values:’totalTime’ and ‘totalHours’ in my for loop are always the same value of the first time ‘converttime was called. I have verified that my ‘converttime’ function is accurately getting the right values but I am not sure how to get the values to change in my for loop.
My code looks like this:
@echo off
set duration=01:25:45
call :converttime %duration%
set /A duration=%totalHours%+%totalMins%
FOR /F "tokens=2 delims=#" %%i IN (subtitle.txt) DO (
call :converttime %%i
set /A totalTime=%totalMins%+%totalhours%
echo %totalTime%
)
endlocal
goto :eof
:converttime
set mytime=%1
set hour=%mytime:~0,2%
set minute=%mytime:~3,2%
set seconds=%mytime:~6,7%
if NOT "%minute%"=="" (
SET /A totalMins=%minute%*60000
)
if NOT "%hour%"=="~0,2" (
set /A totalhours=%hour%*3600000
)
The output is:
4500000
4500000
4500000
4500000
4500000
4500000
When it should be something like:
2500000
3520000
1450000
Any Ideas??
I got it. I just needed to use the ‘setLocal’ command. and surround my variables with ! instead of %
My completed code looks like this: