Page 1 of 1
Resetting multiple variables at once
Posted: 09 Nov 2016 14:57
by batchcc
I have a batch file with a large amount of variables now rather than adding this to the beginning of the file is there an easy way to resset all the variables?
Code: Select all
set var1=
set var2=
set var3=
set var4=
set var5=
set var6=
set var7=
set var8=
...
Thank you!
Re: Resetting multiple variables at once
Posted: 09 Nov 2016 16:10
by aGerman
You have to undefine them separately but you could use loops.
Code: Select all
for /l %%i in (1 1 8) do set "var%%i="
or
Code: Select all
for /f "delims==" %%i in ('set var') do set "%%i="
or
Code: Select all
for %%i in (a_variable another_variable another_different_variable) do set "%%i="
Steffen
Re: Resetting multiple variables at once
Posted: 09 Nov 2016 16:26
by dbenham
The only time you don't need individual SET statements is when you are initializing a series of numeric values. For example, you could initialize four variables to 0:
Dave Benham
Re: Resetting multiple variables at once
Posted: 09 Nov 2016 18:07
by batchcc
Thanks

Re: Resetting multiple variables at once
Posted: 10 Nov 2016 04:29
by Sponge Belly
Hello All!

Check out
this technique developed by Aacini.
- SB