Read parameters from files

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
irinaonline
Posts: 2
Joined: 09 Feb 2018 14:46

Read parameters from files

#1 Post by irinaonline » 09 Feb 2018 14:59

Dear forum,

I am having some troubles with the following situation:

I have a folder with .ini files. Each file contains parameters in the first line. These parameters are delimited by a space (could be changed to a comma). Parameters which contain text and spaces are surrounded by quotes.

With

Code: Select all

for %%a in ("%PROOT%\- Presets\- Presets TYPE\*.INI") do (
  set /p val=<%%a
  set /pz=<%%a
  echo %%~na: %%~na !z!
)
I am able to walk through the directory and echo the filenames and the first line as a whole.

With

Code: Select all

FOR /F "usebackq tokens=6-7 delims=," %%B IN ("%PROOT%\- Presets\- Presets TYPE\1S.INI") DO (set p1=%%~B&set p2=%%~C&set p3=%%~D&set p4=%%~E&set p5=%%~F&set p6=%%~G&set p7=%%~H&set p8=%%~I&set p9=%%~J)
echo %p1%: %p2%
I am able to echo the desired parameters, however, I cannot search a whole folder and it seems I am unable to combine both FOR's. I am sure, there is a very simple solution to this, however, I am unable to find the correct syntax.

Who can help?

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Read parameters from files

#2 Post by penpen » 10 Feb 2018 13:48

WIthout access to any sample data the following might or might not work:

Code: Select all

for %%a in ("%PROOT%\- Presets\- Presets TYPE\*.INI") do (
  set /p val=<%%a
  set /pz=<%%a
  echo %%~na: %%~na !z!
  FOR /F "tokens=6-7 delims=," %%B IN ("%PROOT%\- Presets\- Presets TYPE\1S.INI") DO (set p1=%%~B&set p2=%%~C&set p3=%%~D&set p4=%%~E&set p5=%%~F&set p6=%%~G&set p7=%%~H&set p8=%%~I&set p9=%%~J)
  call echo %%p1%%: %%p2%%
)
(Note that your for/f-loop should only access the tokens 6 and 7, but you set more than just this token - which might be correct or not depending on this for/f-loop's environment.)

penpen

irinaonline
Posts: 2
Joined: 09 Feb 2018 14:46

Re: Read parameters from files

#3 Post by irinaonline » 11 Feb 2018 03:13

penepen,

for %%a in ("%PROOT%\- Presets\- Presets TYPE\*.INI") do (
set /pz=<%%a
FOR /F "usebackq tokens=6-7 delims=," %%B IN ("%%~a") DO (
set p1=%%~B
set p2=%%~C
set p3=%%~D
set p4=%%~E
set p5=%%~F
set p6=%%~G
set p7=%%~H
set p8=%%~I
set p9=%%~J
echo %%~na ... !p2!
)
)

finally worked. It echoes the filename and the 7th parameter of each first line. It works now, still I wonder, if this can be achieved easier, like with just 1 for?

Post Reply