How to list of used variables ?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
H5N1 Bird Flu
Posts: 9
Joined: 23 Jan 2012 14:45

How to list of used variables ?

#1 Post by H5N1 Bird Flu » 08 Feb 2012 03:16

Hi

I want to list of used variables ,but without command SET cause i don´t want to display name of variables just arguments.

etc. I have variables v1 to v18. I want to display arguments of variables from v14 to v18.(just arguments)

for /l %%G in (14,1,18) do (
echo %v%%G%
)

I don´t know correct syntax in echo line....if I want to use variable in variable....

THX for info.....
Last edited by H5N1 Bird Flu on 08 Feb 2012 14:01, edited 1 time in total.

H5N1 Bird Flu
Posts: 9
Joined: 23 Jan 2012 14:45

Re: How to list of used variables ?

#2 Post by H5N1 Bird Flu » 08 Feb 2012 04:15

OK....I solved my self....

Correct form:

for /l %%G in (14,1,18) do (
echo !v%%G!
)
Last edited by H5N1 Bird Flu on 08 Feb 2012 14:01, edited 1 time in total.

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: How to list of used variables ?

#3 Post by Squashman » 08 Feb 2012 06:53

Code: Select all

for /f "tokens=1,2 delims==" %%G in ('set v') do echo %%H

This would give you all the contents of the variables that start with v.
Now if you just wanted 14 through 18 you could set a counter variable and use that in the For Loop. After the For Loop you could check the counter variable to see if it is less than 18 and then GOTO a label before the FOR command. Not as efficient as using delayed expansion and a FOR /L loop but I just wanted to prove that yes you could use a SET command to do it.

You could also hard code all the variables if you really wanted.

Code: Select all

for %G in (%v14% %v15% %v16% %v17% %v18%) do echo %G

H5N1 Bird Flu
Posts: 9
Joined: 23 Jan 2012 14:45

Re: How to list of used variables ?

#4 Post by H5N1 Bird Flu » 08 Feb 2012 14:14

OK..thx for reply :)

....the first solution shows that it is possible also with SET command :)

...but I can´t use hard code of variables cause I don´t know how many variables will be there finally. It´s up to user when he sets ini file ,from which batch file is loading variables....

Post Reply