Function Reference

IniWriteSection

Writes a section to a standard format .ini file.

IniWriteSection ( "filename", "section", "data" [, index ] )

 

Parameters

filename The filename of the .ini file.
section The section name in the .ini file.
data The data to write. The data can either be a string or an array. If the data is a string, then each key=value pair must be delimited by @LF. If the data is an array, the array must be 2-dimensional and the second dimension must be 2 elements.
index If an array is passed as data, this specifies the index to start writing from. By default, this is 1 so that the return value of IniReadSection() can be used immediately. For manually created arrays, this value may need to be different depending on how the array was created. This parameter is ignored if a string is passed as data.

 

Return Value

Success: Returns 1.
Failure: Returns 0. The function will set @error to 1 if the data format is invalid.

 

Remarks

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

If file does not exist, it is created. Any directories that do not exist, will not be created. Keys and/or sections are added to the end and are not sorted in any way."?
If the section being written already exists, it's contents will be overwritten.

 

Related

IniDelete, IniRead, FileWriteLine, IniReadSection, IniReadSectionNames, IniWrite

 

Example


; This is the INI file we will write to.  It will be created on the Desktop.
$sIni = @DesktopDir & "\AutoIt-Test.ini"

; Demonstrate creating a new section using a string as input.
$sData = "Key1=Value1" & @LF & "Key2=Value2" & @LF & "Key3=Value3"
IniWriteSection($sIni, "Section1", $sData)

; Demonstrate creating a new section using an array as input.
$aData1 = IniReadSection($sIni, "Section1") ; Read in what we just wrote above.
For $i = 1 To UBound($aData1) - 1
    $aData1[$i][1] &= "-" & $i  ; Change the data some
Next

IniWriteSection($sIni, "Section2", $aData1) ; Write to a new section.

; Demonstrate creating an array manually and using it as input.
Dim $aData2[3][2] = [ [ "FirstKey", "FirstValue" ], [ "SecondKey", "SecondValue" ], [ "ThirdKey", "ThirdValue" ] ]
; Since the array we made starts at element 0, we need to tell IniWriteSection() to start writing from element 0.
IniWriteSection($sIni, "Section3", $aData2, 0)