Writes a section to a standard format .ini file.
IniWriteSection ( "filename", "section", "data" [, index = 1] )
|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||[optional] 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.|
|Failure:||0. The function will sets the @error flag to 1 if the data format is invalid.|
A standard ini file looks like:
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, its contents will be overwritten.
If you want to use an ini file with unicode encoding, first create an .ini file by using the FileOpen() function with the mode parameter set to "Unicode UTF16 Little Endian".
IniDelete, IniRead, IniReadSection, IniReadSectionNames, IniRenameSection, IniWrite
#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 an array. The zeroth element is how many items are in the array, in this case 3. Local $aSection = [[3, ""], ["Title", "AutoIt"], ["Version", @AutoItVersion], ["OS", @OSVersion]] ; Write the array to the section labelled 'General'. IniWriteSection($sFilePath, "General", $aSection) ; 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 MsgBox($MB_SYSTEMMODAL, "", "Key: " & $aArray[$i] & @CRLF & "Value: " & $aArray[$i]) Next EndIf ; Delete the INI file. FileDelete($sFilePath) EndFunc ;==>Example