批处理脚本价值观不改变? [英] Batch Script Values not changing?

查看:111
本文介绍了批处理脚本价值观不改变?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个批处理脚本,但无论出于何种原因,一旦一个值被设置在我福尔循环持续出现,并不会更新。我的价值观:TOTALTIME'和'totalHours在我的for循环总是在第一时间converttime被称为相同的值。我已经验证了我的'converttime功能准确地获得正确的价值观,但我不知道如何让价值在我更改循环。

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.

我的code是这样的:

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    
)

输出是:

450
450
450
450
450
450

4500000 4500000 4500000 4500000 4500000 4500000

当它应该是这样的:

2500000
3520000
1450000

2500000 3520000 1450000

任何想法??

推荐答案

我知道了。我只需要使用'SETLOCAL'命令。和环绕我的变量有!代替%

I got it. I just needed to use the 'setLocal' command. and surround my variables with ! instead of %

我完成code是这样的:

My completed code looks like this:

@echo off

set duration=01:25:45
call :converttime %duration%

set /A duration=%totalHours%+%totalMins%
setlocal ENABLEDELAYEDEXPANSION 
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    
)

这篇关于批处理脚本价值观不改变?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆