how to parser the config file


T

thinktwice

here is my config file:
//config.ini
WORKINGDIR=C:\workspace
LOGDIR=C:\log
BUILDDIR=C:\build

for /f "tokens=1,2 delims==" %%i in ('findstr /c:WORKINGDIR=
config.ini') do @set WORKINGDIR=%%j
for /f "tokens=1,2 delims==" %%i in ('findstr /c:LOGDIR= config.ini')
do @set LOGDIR=%%j
for /f "tokens=1,2 delims==" %%i in ('findstr /c:BUILDDIR=
config.ini') do @set BUILDDIR=%%j

but it doesnt work as i think.

findstr /c:WORKINGDIR config.ini
returns "LOGDIR=C:\loge"
i don't know why it returns the next line of my target line? why it
returns C:\loge but not c:\log???
 
Ad

Advertisements

Ad

Advertisements

T

Tom Lavedas

finally i find it's caused by my textedtior, :-/
I suppose this is off target, but a comment about your use of the
config file: As you have constructed it, I would think this is a bit
more efficient way to use it ...

for /f "tokens=*" %%a in (config.ini) do set "%%a"

It works as long as the equations are built without spaces around the
equal signs (and without section headers). Actually, there will be no
errors, even if you use spaces. It's just that the variables will be
named in unexpected ways - with trailing spaces - and the contents
will also contain (leading) spaces.

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top