You are not logged in.
Here is it:
I have a file named temp.txt. It contains:
some=
someone=
something=
trash=
explode=
heavy=
...etc (+30 more lines. All lines use = at end as delimiter).
I want to put every lines as variables at batch.
The result I want:
var1=some
var2=someone
var3=something
var4=trash
var5=explode
var6=heavy
var7=...
.....etc.
I already try this with for command but failed.
How?
Offline
What did your for loop look like? A for loop is exactly what you would want to use, so you were definitely on the right track.
Offline
Oops, I forget how is that failed for loop. Emm... Something like this:
for /f "delims==" %%a in (temp.txt) do (...)
Offline
You're almost there (and for what it's worth, the for loop itself is perfect)!
You're going to want to make a counter variable and use it to create a new variable for each line. Since you're going to be altering a variable's value inside of a code block, you'll also need to enable delayed expansion.
@echo off
setlocal enabledelayedexpansion
set counter=0
for /f "delims==" %%A in (temp.txt) do (
set var[!counter!]=%%A
set /a counter+=1
)
set var
pause
set var will display all variables whose names start with the string "var" - I've just included that to prove that it works.
Offline
It's Working! Thanks.
Offline