Jump to content
donhorn20

search multiple ini's and extract data into table

Recommended Posts

donhorn20

Hi everyone,

Let me first start off by saying I love the many things people have posted and created. I have found many useful things to apply this to at my current job. I usually can find examples and tailor them to my specific needs, but this time I am a little stumped. My coding isn't the greatest and like I said, I can usually find what I need in the help or forums. But this time I am stumped. 

Scenario: I have been tasked to search and extract specific data from our ini files. My problem I run into is doing a global search across all of ini's and extracting the defined data.

The key value I am searching on within each ini file is "HTTPServer". Can someone help me in performing the mass search/extract part.

So far my script will extract the information I need, but it requires me to specify the ini name within the .au3 file. Like I said before, I would like to search the directory for all ini's named "drsys*.ini" and spit out all results

I will attach 2 test.ini files that have been stripped down for simplicity sake that the code will look at. Any help would be greatly appreciated.

#include <Array.au3>
#include <MsgBoxConstants.au3>


;~ Location of specific ini.
;~ **********NOTE: This is a temp location, need it to search for drsys*.ini and extract from all ini within directory defined
$sFile = @DesktopDir & "\drsys0001.ini"

;~ Search the ini for section name containing "HTTPServer"
$sSearch = "HttpServer"

; Get section name from ini
$aSections = IniReadSectionNames($sFile)

; Clear the result variable
$sResult = ""

; Loop through the section names gathering the results
For $i = 1 To $aSections[0]
    ; if we find the search variable in the section name
    If StringInStr($aSections[$i], $sSearch) Then
        ; We get the key/value pairing
        $aKey = IniReadSection($sFile, $aSections[$i])
        ; And add them to the result
        $sResult &= $aKey[1][0] & "=" & $aKey[1][1] & @CRLF
    EndIf
Next

; Results from ini
MsgBox(0, "Result for " & $sSearch, $sResult)

 

 

 

 

 

 

drsys0001.INI

drsys0002.INI

Share this post


Link to post
Share on other sites
l3ill

If I understand correctly...

You could set up your search loop as a Function and call that function from a script using:

_FileListToArray

Loop through the array looking for: "drsys*.ini"

and send those files to your function for parsing...

Share this post


Link to post
Share on other sites
water

Or specify "drsys*.ini" as filter in _FileListToArray. So you get an already filtered array which means you need to call your function for every row in the array.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×