IniWrite

首页  后退  前进

IniWrite
down2

IniWrite

写标准格式的配置文件(*.ini).

 

IniWrite ( "filename", "section", "key", "value" )

参数

filename

目标 .ini 文件名.

section

.ini 文件中的字段名.

key

.ini 文件中的关键字名称.

value

需写入或修改的关键字的值.

返回值

成功:

返回 1.

失败:

返回 0, 文件为只读.

备注

标准 INI 文件结构如下:

[字段名]

关键字=

 

如果文件不存在, 只要该目录存在, 则将创建. 关键字和(或)字段将被添加到最后, 并且不按任何规则排序.

 

当写入一个包括引号("" "" 或 ' ')的值时,则引号必须使用 2 次.

例如: ""这是一个测试"", 结果将产生 "这是一个测试". 使用 IniRead() 或许也类似这样.

 

开头和结尾的空格将被自动过滤掉. 要保留空白, 含有空格的字串必须使用引号.

例如, " 这是一个测试", 将会保留空格, 引号会被自动过滤掉.

 

不能使用多行的值.

 

如果你想使用一个 Unicode 编码 的 ini 文件, 首先创建 .ini 文件, 然后使用 FileOpen() 函数并将模式参数设置为 Unicode.

 

函数示例

#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)
    ; Write the value of 'AutoIt' to the key 'Title' and in the section labelled 'General'.
    IniWrite($sFilePath, "General", "Title", "AutoIt")
    ; Read the INI file for the value of 'Title' in the section labelled 'General'.
    Local $sRead = IniRead($sFilePath, "General", "Title", "Default Value")
    ; Display the value returned by IniRead.
    MsgBox($MB_SYSTEMMODAL, "", "The value of 'Title' in the section labelled 'General' is: " & $sRead)
    ; Delete the key labelled 'Title'.
    IniDelete($sFilePath, "General", "Title")
    ; Read the INI file for the value of 'Title' in the section labelled 'General'.
    $sRead = IniRead($sFilePath, "General", "Title", "Default Value")
    ; Display the value returned by IniRead. Since there is no key stored the value will be the 'Default Value' passed to IniRead.
    MsgBox($MB_SYSTEMMODAL, "", "The value of 'Title' in the section labelled 'General' is: " & $sRead)
    ; Delete the INI file.
    FileDelete($sFilePath)
EndFunc   ;==>Example

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

 

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

参见:

IniDelete, IniRead, IniReadSection, IniReadSectionNames, IniWriteSection, IniRenameSection

例子
copy

exect=IniWrite(EnvGet('COMMANDER_INI'),'WWW','Key','Это~~новое~~值') ;; 写入由值给出的Key键的[WWW]部分中的Wincmd.ini文件

 

exect=IniWrite(EnvGet('COMMANDER_INI'),'WWW','Key',Chr(34)&'Это~~новое~~值'&Chr(34)) ;; 写入键值键的[WWW]部分中的Wincmd.ini文件指定的引号的值

 

exect=$var_a=StringSplit('%%COMMANDER_PATH%%\Bar\000_TCIMG_Test.bar|%%COMMANDER_PATH%%\Bar\084_AU3.bar|%%COMMANDER_PATH%%\Bar\000_TCIMG_Test_Exe.bar','|')||$var_si=EnvGet('COMMANDER_PATH')&'\WinButtonBar.ini'||$var_sb=IniRead('$var_si','Buttonbar','Buttonbar','''')||$var_i=Number(_ArraySearch($var_a,'$var_sb')+1)||$var_i=($var_i>3~~Or~~$var_i=0)?1:$var_i||IniWrite('$var_si','Buttonbar','Buttonbar','$var_a[$var_i]')||IniWrite('$var_si','Buttonbar','Buttonbar',Execute('$var_a[$var_i]')) ;; 将WinButtonBar.ini中的一个圆圈中的3个预定义的.bar路径之一写入[Buttonbar]部分

 

exect=$var_a=StringSplit(StringReplace('??%%COMMANDER_PATH%%\TCIMG.exe?~~?openup??|??%%COMMANDER_PATH%%\Utilities\TotalCom\ChoiceEditor\ChoiceEditor.exe??','?',Chr(34)),'|')||$var_sc=EnvGet('COMMANDER_INI')||$var_sp=IniRead('$var_sc','Configuration','Editor','''')||$var_is=StringInStr('$var_sp','TCIMG')?2:1||IniWrite('$var_sc','Configuration','Editor',$var_a[$var_is]) rstart ;; 重新启动时切换到F4

up2

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