1.

Solve : set variables to a list of data?

Answer»

i want to do something like this

for /f "tokens=1*" %%a in ('%TEMP%\~mdt.txt") set %random%=%%a

but when i do it sets all the LINES in mdt.txt as the same random number
also i need a way of keeping track of these variables any ideas?
You might try creating an array. You can certainly keep track of the upper and lower boundaries of an array easier than using random environmental variable names.

Code: [Select]@echo off
set idx=0
for /f "tokens=1* delims=" %%a in (%temp%\~mdt.txt) do (
call set /a idx=%%idx%%+1
call set array.%%idx%%=%%a
)

I made the assumption that each line in the file was to be saved to the array. You can change this if need be.

thanks .. but its not working, i tryed your code and i kept getting this no matter how i edited it
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
0

so i tryed for /f "tokens=5*" %%a in (%temp%\iris) do set %a%=%%a & set /a a=%a%+1 & goto JJJ1

and i GET the same thing?I am unable to reproduce your results. Did you cut and paste the code or retype it? Actually there should be no OUTPUT at the console. The posted code simply assigns variables in the environment space to value of each line in the file.

After running the code, check your environment (use the set command with no parameters at any prompt). You should find variables named array.1 with the value of the first line in the %temp%\~mdt.txt file, array.2 with the value of the second line, array.3 with the value of the third line, etc. While this is not a true array, it comes close to your original request as the array variable is indexed.

I'm not sure what you can do with these results, you could spit back the file in reverse order, but I'm sure you have something in mind.

PS. I notice that you changed the tokens= value from 1 to 5. Any particular reason?

Note: Environment variables set thru batch files live only as long as the cmd window is open. Also keep in mind that unless the delims= value is OVERRIDDEN, the default is spaces and tabs.hey i appreciate it it works now.. it was my own error not your code


Discussion

No Comment Found