0

I'm trying to figure out how to get this nested loop to work without delayedexpansion. My original block shown below works as intended, but after writing it, I discovered I can't save the changes to my variables after ending the local:

setlocal enabledelayedexpansion
REM Identify annual apps that will be updated
echo Discovering apps to update...
set ANNUALAPPSIZE=0
for /l %%a in (0,1,%APPSIZE%) do (
    set CURRENTAPP=!APP[%%a]!
    for %%b in ("%CURPATH%\Packages\!CURRENTAPP!\*") do (
        echo !%%b! | findstr /c:"IncludeInAnnualUpdates.txt" >nul
        if !errorlevel! equ 0 (
            set "ANNUALAPP[%ANNUALAPPSIZE%]=!CURRENTAPP!"
        )
    )
)
endlocal

The methods I was finding of ending the local while saving the changes made to the ANNUALAPP array did not seem very functional / were very ugly.

I'm this far into re-writing the block and it keeps crashing when it gets to the nested loop:

for /l %%a in (0,1,%APPSIZE%) do (
    call set CURRENTAPP=%%APP[%%a]%%
    for %%b in ("%CURPATH%\Packages\%CURRENTAPP%\*) do (
    pause
    )
)

I tried %%APP[%%a]%% in place of %CURRENTAPP% in the nested for loop. As well as %%CURRENTAPP%% in case it was an expansion thing.

3
  • ...Packages\%CURRENTAPP%\*... has to be delayed (as in your first example) Commented Apr 30 at 5:06
  • It's not clear what you want to do here. Are you trying to return the ANNUALAPP array from the first routine? Are you picky about how it's done (ie. could you use a tempfile?) The second routine has unbalanced rabbits' ears. Commented Apr 30 at 7:29
  • Welcome to StackOverFlow. Please take the tour. Always post a minimal reproducible example of the code you are using so that others can replicate it. Commented Apr 30 at 15:24

1 Answer 1

0

Discovered my problem - classically small fix:

ANNUALAPPSIZE needed to have ! instead of %. The %ANNUALAPPSIZE% isn't what was being incremented, so the index it was assigning to was staying at 0.

set "ANNUALAPP[!ANNUALAPPSIZE!]=!CURRENTAPP!"
Sign up to request clarification or add additional context in comments.

1 Comment

ANNUALAPPSIZE doesn't change in the loop, so delayed expansion isn't needed. (Except you do change it, but omitted that important info & code). Perhaps set "ANNUALAPP[%%a]=... is what you want?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.