Click here for important information about

Solved Set unknown number of variables a variable\number

August 13, 2012 at 03:54:31
Specs: windows xp
hey all...

I have a for loop:

FOR /D %%G in (user*) DO (
echo %%G >> list.txt

which will give me a list of folders with user...that works fine...

how can i assign a number to each one found ?

does this make sense ?

batch file found:


assign user1 the number 1
assign user2 the number 2

can i do all of this within a for loop ?

See More: Set unknown number of variables a variable\number

August 13, 2012 at 18:33:31
you want to load them into an "array"? When you say "assign", that is the generally accepted meaning. Then variable with name: 1 contains value: user1?

@echo off & setlocal enabledelayedexpansion
FOR /D %%G in (user*) DO (
echo %%G >> list.txt
set gg=%%G
call :number
:now, this will show them all AFTER they have been loaded
for /L %%a in (1,1,%c%) do echo !%%a!
goto :eof
set /a c+=1
set %c%=%gg%
goto :eof

also, i did NOT assume that names were in order, so if first one is user10, and second one is user3, then var 1=user10, var 2=user3.

Report •

August 13, 2012 at 19:33:19
✔ Best Answer
:: ===== script starts here ===============
@echo off & setLocal enableDELAYedeXpansioN

pushd "C:\Documents and Settings"
set N=
for /f "tokens=* delims= " %%a in ('dir/b') do (
set/a N+=1
set U!N!=%%a
::====== script ends here =================

Life is too important to be taken seriously.


Report •

August 14, 2012 at 02:47:10
Thanks Guys ? Girls? ....

I asked a fella at work as well who is a programmer and awesome with batch files..

I wanted to use a "counter" also.. but i couldnt work it out, but had to use delayexpansion LOL...

Thanks again.

Report •
Related Solutions

Ask Question