Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 批处理脚本值不更改?_Batch File - Fatal编程技术网

Batch file 批处理脚本值不更改?

Batch file 批处理脚本值不更改?,batch-file,Batch File,我有一个批处理脚本,但不管出于什么原因,一旦在我的foor循环中设置了一个值,它就会持续存在并且不会更新。我的值:'totalTime'和'totalHours'在我的for循环中始终是第一次调用'converttime'时的相同值。我已经验证了我的“converttime”函数是否准确地获得了正确的值,但我不确定如何在for循环中获得要更改的值 我的代码如下所示: @echo off set duration=01:25:45 call :converttime %duration% s

我有一个批处理脚本,但不管出于什么原因,一旦在我的foor循环中设置了一个值,它就会持续存在并且不会更新。我的值:'totalTime'和'totalHours'在我的for循环中始终是第一次调用'converttime'时的相同值。我已经验证了我的“converttime”函数是否准确地获得了正确的值,但我不确定如何在for循环中获得要更改的值

我的代码如下所示:

@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    
)
@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    
)
输出为:

450万 4500000 4500000 4500000 4500000 450万

当它应该是类似于:

2500000 3520000 1450000


有什么想法吗???我明白了。我只需要使用“setLocal”命令。并将我的变量包围起来!而不是%

我完成的代码如下所示:

@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    
)
@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    
)
这被称为“延迟扩展”。