Page 1 of 1

BAT to read multiple .INI from folders and report a setting

Posted: 10 Oct 2011 14:54
by billiehawkins
Request help building a Batch file to read and report a setting from an ini. from a set of folders, and output result to a text file.


I have a set of folders, and in each folder is a INI file with a list of settings.

I am looking for a way to read the INI in each folder, and report back a specific setting in each - perhaps output to a text file.

Example:

Code: Select all

Folder:                    File:          Setting: 
C:\Users\JonesSmith     JonesSmith.ini       maximumlogin=2200
C:\Users\MikeHawk           MikeHawk.ini       maximumlogin=3000
C:\Users\Jenny801            Jenny801.ini       maximumlogin=1500


As you can see, each file name is different, but there is only one INI per folder, and I only need the specific setting out of each. Based on the setup of the user folder, the setting may not be on the same line in each INI

The amount of folders changes daily, as new setups are created. maximumlogin setting is set on the GUI side during the add process, and I need a report that can show them.

In theory, I would like a text file output that shows the result just like the example data above.

I am guessing this can be done with a For /F loop of some sort, but I am terrible at those.

Help?

Re: BAT to read multiple .INI from folders and report a sett

Posted: 10 Oct 2011 16:19
by dbenham
untested:

Code: Select all

@echo off
(
  echo Folder:                    File:          Setting:
  for /d %%D in ("C:\Users\*") do (
    for %%F in ("%%D\*.ini") do (
      for /f "delims=" %%L in ('findstr /i /c:"maximumlogin=" "%%F"') do (
        echo %%D     %%-nxF     %%L
      )
    )
  )
)>maximumLogin_report.txt


Dave Benham

Re: BAT to read multiple .INI from folders and report a sett

Posted: 10 Oct 2011 16:32
by billiehawkins
This worked as expected. I made one change, (personal preference to output) 0 but yes, this works.

Thank you very much.

[SOLVED]