Sign in to follow this  
Followers 0
esco

How to get ini fileSections into one Arra

6 posts in this topic

Hi all ,

I'm twiddling arround to get a solution for this since days but without success.I didn't find any answer in this forum.

So now I'm hoping to get some advices or ideas wth this post.

My goal is to get a result array that contains all sections into one array.

Using IniReadSection returns a 2D Array but I'm failing to combine the result into one Array.

Func getPath($var)
    ;*****************

    $IRS = IniReadSection("RPU.ini", "settings"&$var) 
        If @error Then
            FileWrite($file, "Read ini Error getPath :")
            Exit 0
        EndIf
    Return $IRS
EndFunc

ini-FIle

[settings1]

IP=new.address.com

IP_alt=www.gateway.com

TelnetPort=1111

SSL=1

StrictServerAuth=true

EnforceValidityDates=true

TrustedIssuerChain=true

[settings2]

IP=new2.address.com

IP_alt=www.gateway2.com

TelnetPort=2222

SSL=1

StrictServerAuth=true

EnforceValidityDates=true

TrustedIssuerChain=true

Any idea or advice is welcome

Thanks in advance

esco

Share this post


Link to post
Share on other sites



My goal is to get a result array that contains all sections into one array.

What's your desired result? I.e. what do you want each element to contain? E.g. a line? Or a section?

(The signature is placed on the back of this page to not disturb the flow of the thread.)

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

So something like this?

#include <Array.au3>
Global $aCombined[1][2]

_GetPath()

_ArrayDisplay ($aCombined)

Func _GetPath()
    $sections = IniReadSectionNames ("test.ini")
    For $x = 1 to $sections[0]
        $section = IniReadSection("test.ini", $sections[$x])
        If Not @error Then
            $varStart = UBound($aCombined)-1
            ReDim $aCombined[UBound($aCombined)+$section[0][0]][2]
            For $y = 1 To $section[0][0]
                $aCombined[$varStart][0] = $section[$y][0]
                $aCombined[$varStart][1] = $section[$y][1]
                $varStart += 1
            Next
        EndIf
    Next
EndFunc
Edited by exodius

Share this post


Link to post
Share on other sites

What's your desired result? I.e. what do you want each element to contain? E.g. a line? Or a section?

I something like this:

result array: (see pic)

row col0 col1

[0] 14

[1] IP new.address.com

[2] IP_alt www.gateway.com

[3] TelnetPort 1111

[4] SSL 1

[5] StrictS.. true

[6] EnforceV.. true

[7] Trusted.. true

[8]

[9] IP new2.address.com

[10] IP_alt www.gateway2.com

[11] TelnetPort 2222

[12] SSL SSL

[13] StrictS.. true

[14] EnforceV.. true

[15] Trusted.. true

Share this post


Link to post
Share on other sites

So something like this?

#include <Array.au3>
Global $aCombined[1][2]

_GetPath()

_ArrayDisplay ($aCombined)

Func _GetPath()
    $sections = IniReadSectionNames ("test.ini")
    For $x = 1 to $sections[0]
        $section = IniReadSection("test.ini", $sections[$x])
        If Not @error Then
            $varStart = UBound($aCombined)-1
            ReDim $aCombined[UBound($aCombined)+$section[0][0]][2]
            For $y = 1 To $section[0][0]
                $aCombined[$varStart][0] = $section[$y][0]
                $aCombined[$varStart][1] = $section[$y][1]
                $varStart += 1
            Next
        EndIf
    Next
EndFunc

Wow, yes yes exacly! What I need

Thank you exodius

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Another version

#include <Array.au3>

$aKeys = GetKeys(@ScriptDir & "\test.ini")

_ArrayDisplay($aKeys)

Func GetKeys($sIniFile)
    Return StringSplit(StringRegExpReplace(FileRead($sIniFile), '(?m)(^\s*\r\n)|(^\[.+\]\r\n)|((\r\n)*\z)|(^\s*;.*?\r\n)', ''), @CRLF, 1)
EndFunc
Edit: change regexp to also handle comment and whitespace only lines Edited by picaxe

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
Sign in to follow this  
Followers 0