数组值与子字符串比较(批处理脚本)不匹配

时间:2017-02-03 09:56:36

标签: arrays batch-file if-statement substring expansion

我有以下代码脚本:

set "file=%cd%/Config.mak"
set /a i=0
set /a j=0

@REM Delete the file if it currently exists in the folder:
IF EXIST Disabled_Features.txt del /F Disabled_Features.txt
@REM If the file can't be deleted, exit with an error:
IF EXIST Disabled_Features.txt exit 1

setlocal EnableDelayedExpansion EnableExtensions

@REM Parse Features from Config.xml into string array.
for /f "usebackq delims=" %%a in ("%file%") do (
    call set /a i+=1
    call set Feature[%i%]=%%a
)   

@REM Regexr parametre
call set "search=:=$"

@REM Keep the Disabled Features into new array for stripping module:
for /L %%N in (1,1,%i%) do (
    echo(!Feature[%%N]!|findstr /R /C:"%search%">nul && (
        call echo FOUND
        call set /A j+=1
        call set Feature_Disabled[%j%]=!Feature[%%N]:~0,-2!
        call echo.!Feature_Disabled[%j%]!>>Disabled_Features.txt
    ) || (
        call echo NOT FOUND 
    )
) 
endlocal

我能够打印并访问第一个"for"指令数组值,这意味着它们是从文件中正确收集的,但是当涉及第二个"for"指令时,指令{{ 1}}似乎没有将正确的值传递给!Feature[%%N]!,因为正则表达式是findstr,它匹配行尾的字符':=$'和数组值的格式如下:

':='

因此,在这种情况下,EXAMPLE_SAMPLE1:=x5 EXAMPLE_SAMPLE2:= EXAMPLE_SAMPLE3:=asdadasd 应匹配字符串数组的第二个值。

每当我尝试命令(调试)时:

findstr

输出显示:

 call echo.!Feature[%%N]!

是否指出了适当的解决方案?

非常感谢你。

0 个答案:

没有答案