我有一个名为a.ini
的文件,其中包含两个部分:
[Section1]
name1=abc
name2=xyz
name3=def
[Section2]
class1=1st
class2=2nd
class3=3rd
我希望使用autoit来获取以下输出:
abc 1st
xyz 2nd
def 3rd
使用以下代码,我只获得abc
,xyz
,def
。如何同时从两个部分同时阅读?
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
答案 0 :(得分: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