PDA

View Full Version : Working with .ini configuration files



barrymavin
2012-10-15, 08:20
Lianja scripting includes a group of cross-platform functions for handling windows-style .ini text files.

Sets a key/value pair in a section of an ini/configuration file


ini_set(Section as character, Key as character, Value as character[, Filename as character]) as logical


Gets a value for a key in a section of an ini/configuration file


ini_get( Section as character, Key as character[[[, Default as character], Filename as character], Macros as logical]) as character


Sets all key/value pairs for a section of an ini/configuration file


ini_setsection(object as object, Section as character[, Filename as character]) as logical


Gets all key/value pairs for a section of an ini/configuration file


ini_getsection(Section as character[[, Filename as character], Macros as logical]) as object

A typical ini/configuration file looks like this:

Here is an example .ini file:



# comment lines are preceeded by a '#'
; or a ';'
#
# "Sections" are enclosed in [ and ]
[global]
; key/value pairs are contained in the sections and are written like this
key1 = value
key2 = value2
; You can include macros in the key/value pairs.
key3 = This is $(key2) and $(key1)


Notes:

It "Macros" is not specified both ini_get( ) and ini_getsection( ) will not expand macros. Set it to true if you want macros expanded

ini_getsection( ) returns an object (Associative array) which allows you to reference key/value pairs, update them, and write them back to the configuration file.