esco Posted October 10, 2009 Share Posted October 10, 2009 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 Link to comment Share on other sites More sharing options...
memoryoverflow Posted October 10, 2009 Share Posted October 10, 2009 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.) Link to comment Share on other sites More sharing options...
exodius Posted October 10, 2009 Share Posted October 10, 2009 (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 October 10, 2009 by exodius Link to comment Share on other sites More sharing options...
esco Posted October 10, 2009 Author Share Posted October 10, 2009 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 Link to comment Share on other sites More sharing options...
esco Posted October 10, 2009 Author Share Posted October 10, 2009 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 Link to comment Share on other sites More sharing options...
picaxe Posted October 10, 2009 Share Posted October 10, 2009 (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) EndFuncEdit: change regexp to also handle comment and whitespace only lines Edited October 10, 2009 by picaxe Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now