How to increment a numeric value using SET /A inside nested FOR in Windows Command Prompt batch file?

StackOverflow https://stackoverflow.com/questions/17643826

문제

This is my batch script:

set vc11path=C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC
set path=%path%;C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE
set path=%path%;%vc11path%\bin
set path=%path%;G:\ida61\flair61\bin\win
set /a "count = 1"

cd "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\lib"
c:
for %%i IN (*.lib) DO (
 md a:\libs\%%i.fdr
)

for %%i IN (*.lib) DO (
    for /F "skip=3" %%j in ('link.exe -lib /list %%i') do (
        link.exe -lib /extract:%%j "%vc11path%\lib\%%i" /OUT:"a:\libs\%%i.fdr\%%~nj.n%count%.obj"
        set /a "count+=1"
    )
)

FOR /D %%i IN ("a:\libs\*.fdr") DO for %%j in (%%i\*.obj) do pcf.exe -g0 "%%i\%%~nj.obj"

FOR /D %%i IN ("a:\libs\*.fdr") DO sigmake %%i\*.pat a:\libs\%%~ni.sig

I'm trying to increment count value using set /a "count+=1" in inner loop, but it seems that this command has no effect to increment that variable.

Sorry for my poor English.

도움이 되었습니까?

해결책

You need to enable delayed expansion if you want variables expanded at runtime. Add this line at the beginning of your script:

setlocal EnableDelayedExpansion

and replace %count% inside loops and conditionals with !count!.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top