你的问题不清楚。我不明白“我需要再次设置一些变量的值”是什么意思。你应该描述你的期望和你真正得到的。出于这个原因,我无法为您的问题提供确切的答案,而仅提供一系列示例:
echo off
setlocal EnableDelayedExpansion
rem The target variable is "b1" or "b2", depending on *current* value of "i":
set i=1
set b1=var1
set b2=var2
call echo %%b%i%%%
rem This works, but only *outside parentheses*
set b%i%=var1changed
call echo %%b%i%%%
rem Inside paren, this works only when "i" var is not changed:
(
set b%i%=var1changed again
call echo %%b%i%%%
set i=2
set b%i%=wrong: this should be b2, but it is b1
call echo %%b%i%%%
)
set b
rem Using delayed expansion for the index works always:
(
set i=1
set b!i!=var1 again, inside paren
call echo %%b!i!%%
set i=2
set b!i!=var2changed
call echo %%b!i!%%
)
set b
输出:
var1
var1changed
var1changed again
wrong: this should be b2, but it is b1
b1=wrong: this should be b2, but it is b1
b2=var2
var1 again, inside paren
var2changed
b1=var1 again, inside paren
b2=var2changed
您也可以使用FOR /F
命令进行此管理。此答案的更多详细信息。