Batch: Text file -> Environment variable?
Have an INI file with contents like:
Code:
Alice=One2Three
Bob=Four5Six
I want to pick one entry e.g. Bob and put it in an environment variable. This works:
Code:
for /f "usebackq tokens=2 delims==" %%i in (`findstr Bob file.ini`) do set Bob=%%i
Took me a teensy while to arrive there having first failed with other approaches. Has anyone ever got "other approaches" to work or is this pretty much what you have to do?
Re: Batch: Text file -> Environment variable?
That's pretty much exactly how I'd do it... What other approaches did you try? Would be interesting to see if there's anything which could be hacked around a bit another time.
Re: Batch: Text file -> Environment variable?
Simple and works seems like a winner to me.
Ben
Re: Batch: Text file -> Environment variable?
So if tom, Dick and Harry each had their own variables would it work as good hehe ;)
Re: Batch: Text file -> Environment variable?
Nice bit of code.
I'm getting to grips with AutoIt - that has specific functions for reading / writing .INI files. I recommend it.
Or you could use a separate initool.exe such as this:- http://www.jsifaq.com/SF/Tips/Tip.aspx?id=7373
Re: Batch: Text file -> Environment variable?
Quote:
What other approaches did you try?
Oh I had loads of fun trying and failing to pipe and redirect the output of 'find' or 'findstr' to 'set' etc.
Suspect my heart is stuck in early DOS days because "for /f.." just feels more complicated.