1

I have file called a.ini containing two section :

[Section1]
name1=abc
name2=xyz
name3=def

[Section2]
class1=1st
class2=2nd
class3=3rd

I want to get this in to following output using autoit:

abc 1st
xyz 2nd
def 3rd

With the following code I am getting only abc, xyz, def. How do I read at the same time from both sections simultaneously?

Local $var = IniReadSection(@ScriptDir & "a.ini", "section1")
If @error Then
    MsgBox(4096, "", "Error occurred, probably no INI file.")
Else
    For $i = 1 To $var[0][0]
        MsgBox(4096, "", "Key: " & $var[$i][0] & @CRLF & "Value: " & $var[$i][1])
    Next
EndIf
4

1 回答 1

2

以下代码将使用IniReadSectionNames读取所有部分,然后在每个部分上循环时,使用 IniReadSection 读取

Local $sections = IniReadSectionNames(@WindowsDir & "\win.ini")
If @error Then
    MsgBox(4096, "", "Error occurred, probably no INI file.")
Else
    For $i = 1 To $sections[0]

        Local $values = IniReadSection(@WindowsDir & "\win.ini", $sections[$i])
        If @error Then
            ConsoleWrite("SECTION " & $sections[$i] & ": is EMPTY!" & @LF)
            ContinueLoop
        EndIf
        For $i2 = 1 To $values[0][0]
            ConsoleWrite("SECTION " & $sections[$i] & ": Key: " & $values[$i2][0] & "=" & $values[$i2][1] & @LF)
        Next

    Next
EndIf
于 2013-10-21T11:11:50.797 回答