Batch File For Loop Problem

December 27, 2009 at 15:22:02
Specs: Windows Vista
Hello,

i've got a problem. I have a text file named 'save1.txt'. it's contents are:

$cabsexp=0
$churexp=0
$grifexp=0
$name=Test
$sargexp=0
$simsexp=0
$team=yellow

i need a for loop that executes each line with a 'set' command before it.

i was originally given:
for /f "tokens=*" %a in (save1.txt) do set %a

but that didn't work. i have since tried these:
for /f %%g in ("save1.txt") do set %%g
FOR /F %%G IN ('"D:\Groups\Batch Files\RPG\save1.txt"') DO SET %%G

none work.
I'm currently using windows vista, but it will need to work on vista, xp and 7.
any ideas??


See More: Batch File For Loop Problem

Report •


#1
December 27, 2009 at 18:46:18
it worked over here (second or third tries).
1) do you want these set into the environment table?
2) what method did you use to confirm the code was not working? (I used:)
set $
pause

and they were all there.


Report •

#2
December 27, 2009 at 21:17:48
For quoted file names "usebackq" must be present.

FOR /F "usebackq delims=" %%G IN ("D:\Groups\Batch Files\RPG\save1.txt") DO SET %%G


Batch Variable how to


Report •

#3
December 27, 2009 at 23:21:48
for /f "tokens=*" %a in (save1.txt) do set %a

Nothing wrong with that.

Unless, of couse, you put it in a batch file, where it will need %%a. NOT %a


=====================================
Helping others achieve escape felicity

M2


Report •

Related Solutions

#4
December 28, 2009 at 06:58:43
judago's one worked!! thx!!

Report •

#5
December 28, 2009 at 14:52:30
I would get rid of that dollar sign as quick as possible ... I mean, if you don't really need it, remove it. I don't mean to change the file, but handling with the names of these vars. What's the odd you have both "$cabsexp" and "cabsexp" in that inputfile ?


C:\>type test.txt
$cabsexp=0

C:\>for /F %f in (test.txt) do echo set %f| sed "s/\$//g"

C:\>echo set $cabsexp=0 | sed "s/\$//g"
set cabsexp=0


I forgot what the global replace command in Windows is, so I used SED

;)


ps, Cab sex ?


Report •

#6
December 28, 2009 at 15:10:11
errr... the dollars are there cause it's the simplist way to save multiple variables to one file using a batch file:

set $>save1.txt


and cabsexp is short for caboose experience, with caboose being a character from Red vs Blue...
it makes sense to me!!


Report •

#7
December 28, 2009 at 15:57:28
cab sex...
caboose experience...

i'm getting out of here!


Report •

#8
December 28, 2009 at 16:49:21
tvc,

This is not unix.


=====================================
Helping others achieve escape felicity

M2


Report •


Ask Question