1.

Solve : More for loop help >.

Answer»

So I DECIDED to restart my program after DROPPING it for awhile. So for the problem I'm stuck on, I need to grab some strings from diffrent points in a text file (I now exactly where) and set a veriable equal to them. So basicly, I need to set everything on the right of the ':' to a veriable that is named something similar to the what is on the left of it. Here's an example of the text file:
Quote from: 1.txt

Name:Lemonilla
Urels:50
Yuin:0
Wenarduls:0
Location:Tipa
Time:1
So far I've got a for /f loop that isn't quite working the way I want it to , It seems to reset the same veriable all the diffrent values, so instead of setting %Name% equal to Lemonilla, It ends up being 1 (as that is the value for the last executed loop, Time). Here is my failed attemp, I feel like i'm just putting the wrong stuff in the "s.
Code: [Select] ::ConfermSave.LoadSave.start
for /f "tokens=1-6" %%D in (%save%.txt) do (
set a=%%D
set name=!a:~5,100!
set a=%%E
set Urels=!a:~6,100!
set a=%%F
set Yuin=!a:~5,100!
set a=%%G
set Wenarduls=!a:~10,100!
set a=%%H
set location=!a:~9,100!
set a=%%I
set _Time=!a:~5,100!
)
Where %save% = 1.Code: [Select]@echo off

FOR /F "tokens=1,2 delims=:" %%G IN (1.txt) do set %%G=%%H

echo %Name%
echo %Urels%
echo %Wenarduls%
echo %Location%
echo %Time%
pauseOutput
Code: [Select]C:\Users\Squashman\Batch\for_loops>loop.bat
Lemonilla
50
0
Tipa
1
Press any key to continue . . .

C:\Users\Squashman\Batch\for_loops>>.< I guess I was thinking too hard... Thanks for the help!I wouldn't say you were thinking to hard. You just were not understanding how for loops parse text files. Your code makes me think you thought the for loop parses th whole text file at once which it doesn't. It processes one line at a time.Quote from: Squashman on DECEMBER 01, 2012, 11:11:40 AM
I wouldn't say you were thinking to hard. You just were not understanding how for loops parse text files. Your code makes me think you thought the for loop parses th whole text file at once which it doesn't. It processes one line at a time.

From the FOR documentation (type FOR /? at the prompt:)

FOR /F ["options"] %VARIABLE IN (file-set) DO command [command-parameters]
FOR /F ["options"] %variable IN ('string') DO command [command-parameters]
FOR /F ["options"] %variable IN (`command`) DO command [command-parameters]

file-set is one or more file names. Each file is opened, read
and processed before GOING on to the next file in file-set.
Processing consists of reading in the file, breaking it up into
individual lines of text and then parsing each line into zero or
more tokens. The body of the for loop is then called with the
variable value(s) set to the found token string(s). By default, /F
passes the first blank separated token from each line of each file.
Blank lines are skipped. ...
No fair, I was really tired that day


Discussion

No Comment Found