Function Reference


IniReadSection

Reads all key/value pairs from a section in a standard format .ini file.

IniReadSection ( "filename", "section" )

Parameters

filename The filename of the .ini file.
section The section name in the .ini file.

Return Value

Success: a 2 dimensional array where element[n][0] is the key and element[n][1] is the value.
Failure: sets the @error flag to non-zero if unable to read the section (The INI file may not exist or the section may not exist or is empty)

Remarks

A standard ini file looks like:
[SectionName]
Key=Value


The number of elements returned will be in $aArray[0][0]. If an @error occurs, no array is created.
    $aArray[0][0] = Number
    $aArray[1][0] = 1st Key
    $aArray[1][1] = 1st Value
    $aArray[2][0] = 2nd Key
    $aArray[2][1] = 2nd Value
    ...
    $aArray[n][0] = nth Key
    $aArray[n][1] = nth Value

Only the first 32767 chars are read for legacy reasons.

Related

IniDelete, IniRead, IniReadSectionNames, IniRenameSection, IniWrite, IniWriteSection

Example

#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>

Example()

Func Example()
        ; Create a constant variable in Local scope of the filepath that will be read/written to.
        Local Const $sFilePath = _WinAPI_GetTempFileName(@TempDir)

        ; Create an INI section structure as a string.
        Local $sSection = "Title=AutoIt" & @LF & "Version=" & @AutoItVersion & @LF & "OS=" & @OSVersion

        ; Write the string to the section labelled 'General'.
        IniWriteSection($sFilePath, "General", $sSection)

        ; Read the INI section labelled 'General'. This will return a 2 dimensional array.
        Local $aArray = IniReadSection($sFilePath, "General")

        ; Check if an error occurred.
        If Not @error Then
                ; Enumerate through the array displaying the keys and their respective values.
                For $i = 1 To $aArray[0][0]
                        MsgBox($MB_SYSTEMMODAL, "", "Key: " & $aArray[$i][0] & @CRLF & "Value: " & $aArray[$i][1])
                Next
        EndIf

        ; Delete the INI file.
        FileDelete($sFilePath)
EndFunc   ;==>Example