0

I want to make a variable Variable, which means that i want to create many variables with variable names, e.g. Var1, Var2, Var3, Var4. This works (see below), but ECHOing was not working since i have to use EnableDelayedExpansion due to single handling within the FOR-Loop and !var%num%! was not interpreted correctly.

So here is what i've got:

SetLocal EnableDelayedExpansion

SET /a num = 0
FOR /F "tokens=*" %%a IN ('dir /b *.bat') DO (
    SET /a num = num + 1
    SET var!num!=%%a
    CALL ECHO No. !num!^: %%var!num!%%
    )

EndLocal DisableDelayedExpansion

After hours, this works now using the CALL-Routine in front of echo

My question to you guys out there is now how to make

    CALL ECHO No. !num!^: %%var!num!%%

a little nicer. I first tried

    ECHO No. !Num!^: !var%num%!

but this fails as it is in on single FOR-Loop. Is there any opportunity to make this nicer than CALLING it?

Thank you in advance Patrick

2

1 Answer 1

3
SetLocal EnableDelayedExpansion

SET /a "num=0"

FOR /F "delims=" %%a IN ('dir /b *.bat') DO (
    SET /a "num+=1"
    SET "var!num!=%%a"
    FOR %%b in (!num!) do ECHO No. !num!: !var%%b!
)

EndLocal 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.