数组索引不返回该值

时间:2016-09-08 12:22:18

标签: batch-file

我有两个文本文件,一个存储我需要复制的文件的名称,另一个存储我要复制它们的地址。我的想法是创建两个数组来存储该信息,然后循环遍历它们,以便我总是得到文件名和相应的地址。这是我用来在数组中存储信息的代码:

@echo off
set /A i=0
set x=0

for /F "usebackq delims=" %%a in ("Name.txt") do (
    set /A i+=1
    call echo %%i%%
    call set NAME_ARRAY[%%i%%]=%%a
    call set n=%%i%%
)

set /A i=0

for /F "usebackq delims=" %%a in ("Adress.txt") do (
    set /A i+=1
    call echo %%i%%
    call set ADRESS_ARRAY[%%i%%]=%%a
    call set n=%%i%%
)

然后我遍历两个数组并尝试用它们做事:

for /L %%j in (1,1,%n%) do (
:: subproject dir, relative to the sandobox dir
set SUBPROJECT_DIR=%ADRESS_ARRAY[%%j]%
:: sandbox name
set SANDBOX_NAME=C:\%SANDBOX_FOLDER_NAME%\%SUBPROJECT_DIR%\project.pj
:: name of sandbox folder
set SANDBOX_DIR=C:\%SANDBOX_FOLDER_NAME%\%SUBPROJECT_DIR%
:: name of presentation to be copied
set PRESENTATION_NAME=%NAME_ARRAY[%%j]%

:: check out file with software version number
si co --sandbox=%SANDBOX_NAME% --changePackageId=:none --hostname=%SERVERNAME% --port=%PORTNAME%  %SANDBOX_DIR%\%PRESENTATION_NAME%

:: Copying new files (Option /xo of robocopy)
robocopy x: %SANDBOX_DIR% %PRESENTATION_NAME%

:: check in modified file
si ci --sandbox=%SANDBOX_NAME% --changePackageId=:none --hostname=%SERVERNAME% --port=%PORTNAME% %SANDBOX_DIR%\%PRESENTATION_NAME%
)

我的问题是,我似乎无法通过索引读取数组。 set SUBPROJECT_DIR=%ADRESS_ARRAY[%%j]%set PRESENTATION_NAME=%NAME_ARRAY[%%j]%似乎没有设置变量,它们仍为空。有人知道为什么吗?

1 个答案:

答案 0 :(得分:1)

你的建议让我走上正轨。这是现在正在运行的版本,以防其他人遇到同样的问题:

{{1}}