繁体   English   中英

带有数组的变量中的Windows批处理变量

[英]Windows Batch Variable within variable with array

我有以下代码:

setlocal enableDelayedExpansion
call :Retrieve Test
goto eof
:Retrieve <StringVar>
set /a Count_%1=2

这导致(在带有echo的命令窗口中):

set /a Count_Test=2
echo !Count_%1!

这导致:

set "file_%1[!Count_%1!]=*.txt"

这导致(在带有echo的命令窗口中):

set "file_Test[!Count_Test!]=*.txt"

但是,它应该是:

set "file_Test[2]=*.txt"
set file_%1[

结果是:

环境变量文件 - 测试[未定义

goto eof
:eof

有谁知道我做错了什么?!? 完整代码如下:

setlocal enableDelayedExpansion
call :Retrieve Test
goto eof
:Retrieve <StringVar>
set /a Count_%1=2
echo !Count_%1!
set "file_%1[!Count_%1!]=*.txt"
set file_%1[
goto eof
:eof

对不起我的编辑,我是新来的...

我的问题是关于这一行: set "file_%1[!Count_%1!]=*.txt" ,其余的行都可以,我的原始脚本的样本。

尝试

set file_%1[

代替

set file-%1[

(如果你使用正确的变量名,可以帮助一点)

修好了......

call set "file_%1[!Count_%1!]=*.txt"

诀窍......

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM