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

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
billiehawkins
Posts: 3
Joined: 10 Oct 2011 14:26

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

#1 Post by billiehawkins » 10 Oct 2011 14:54

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?

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

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

#2 Post by dbenham » 10 Oct 2011 16:19

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

billiehawkins
Posts: 3
Joined: 10 Oct 2011 14:26

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

#3 Post by billiehawkins » 10 Oct 2011 16:32

This worked as expected. I made one change, (personal preference to output) 0 but yes, this works.

Thank you very much.

[SOLVED]

Post Reply