IniReadSection

首页  后退  前进

IniReadSection
down2

IniReadSection

读配置文件(*.ini)字段的全部关键字与值.

 

IniReadSection ( "filename", "section" )

参数

filename

目标 .ini 文件名.

section

.ini 文件中的字段名.

返回值

成功:

返回二维数组: 元素[n][0] 储存关键字; 元素 [n][1] 储存对应关键字的值.

失败:

设置 @error 为非 0 值, 无法读取字段(INI文件或字段不存在, 或为空)

备注

标准 INI 文件结构如下:

[字段名]

关键字=值

 

 

本函数返回数组的 $result[0][0] 中储存数组元素的总数. 若遇到 @error 错误, 则该数组不会被创建.

$aArray[0][0] = 元素总数

$aArray[1][0] = 第一关键字

$aArray[1][1] = 第一关键字的值

$aArray[2][0] = 第二关键字

$aArray[2][1] = 第二关键字的值

   ...

$aArray[n][0] = 第 n 关键字

$aArray[n][1] = 第 n 关键字的值

 

由于遗留原因, 仅读取前面的 32767 个字符.

译注: afan 版大有个破解这个限制的 UDF _Ini函数库

 

 

 

本函数返回数组的 $result[0][0] 中储存数组元素的总数. 若遇到 @error 错误, 则该数组不会被创建.

$aArray[0][0] = 元素总数

$aArray[1][0] = 第一关键字

$aArray[1][1] = 第一关键字的值

$aArray[2][0] = 第二关键字

$aArray[2][1] = 第二关键字的值

   ...

$aArray[n][0] = 第 n 关键字

$aArray[n][1] = 第 n 关键字的值

 

由于遗留原因, 仅读取前面的 32767 个字符.

译注: afan 版大有个破解这个限制的 UDF _Ini函数库

 

函数示例

#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

----------------------------------------

 

该函数可以通过命令 exect 调用

参见:

IniDelete, IniWrite, IniRead, IniReadSectionNames, IniRenameSection, IniWriteSection

例子
copy

exect=$var_aa=IniReadSection(EnvGet('COMMANDER_INI'),'Configuration')||_ViewValues($var_aa) ;; 从配置部分读取Wincmd.ini中的所有对参数=值

up2

tcimage © Аверин Андрей для Total Commander Image Averin-And@yandex.ru