Skip to content

Ini

Reads value(s) from an ini file located in a relative or absolute path.

Forms

string Ini[filename,section,key,default]

The section, key, and default do not need to be given. If section or key are not given, multiple values are read.

Section and key may be set to -1 to skip them and give a new value.

If the ini is located in a directory other than the root Macros directory is located, you can use a DOS-style filepath (relative or absolute) to locate the ini. If the macro accessing the ini is in the same non-root directory, you will still to provide the (relative or absolute) filepath.

ini Ini

When passed with no parameters to Ini[] the more robust form of the Ini TLO is used. See below and the reference to the Key datatype for further usage.

Associated DataTypes

ini

This is the type for an ini that you have referenced without an Index.

Members

inifile File

The ini file you would like to reference. ".ini" is appended if there is no extension.

Relative and absolute paths are allowed. Searching is performed using the macro directory and the config directory for relative paths.

inifile

This is the type for the ini file that was referenced from TLO:Ini

Members

bool Exists

Whether the ini file exists or not.

inifilesection Section[opt: Section]

A reference to the named or unnamed section of this ini file.

The index is optional. Passing an index means it will search for matches to that index. Not passing an index references all sections for operations that allow it.

inifilesection

This is the type for the referenced section of an ini file.

Members

int Count

How many sections matching the Section[] index exist.

bool Exists

Whether a specific section exists.

inifilesectionkey Key[opt: Key]

A reference to the named or unnamed key in this specific ini file section.

The index is optional. Passing an index means it will reference all keys that match that index. Not passing an index references all keys for operations that allow it.

inifilesectionkey

This is the type for the referenced key in a specific section of an ini file.

Members

int Count

How many keys matching the Key[] index exist.

bool Exists

Whether a specific key exists.

string Value

The value for a specific key. Accepts an Index to allow for returning a value if the key does not exist

string KeyAtIndex

The name of the key at the specified index

string ValueAtIndex

The value of the entry at the specified index

Usage

If sample.ini contains:

[SectionOne]
key1=foo
key2=bar
[SectionTwo]
key3=foobar
/echo ${Ini[sample.ini,SectionOne,key1]}

foo

/echo ${Ini[sample.ini,SectionOne]}

key1|key2||

/echo ${Ini[..\sample.ini]}

SectionOne|SectionTwo||

If sample.ini is in \Macros\iniTest folder:

/echo ${Ini[sample.ini]}

NULL

/echo ${Ini[iniTest\sample.ini]}

SectionOne|SectionTwo||

Ini (Robust Usage)

The above form of Ini usage is usable or most tasks, but a more robust usage exists. In the more robust form ${Ini} returns an IniType instead of a string. This allows for dealing with duplicate keys as well as looping through a section by index.

Examples

If sample.ini contains:

[SectionOne]
key1=foo
key=bar
key=foobar
> /echo ${Ini.File[sample].Section.Count}
1
> /echo ${Ini.File[sample].Section[SectionOne].Key.Count}
3
> /echo ${Ini.File[sample].Section[SectionOne].Key[key].Count}
2
> /echo ${Ini.File[sample].Section[SectionOne].Key[key1].Value}
foo
> /echo ${Ini.File[sample].Section[SectionOne].Key[key].ValueAtIndex[2]}
foobar
> /echo ${Ini.File[sample].Section[SectionOne].Key.ValueAtIndex[2]}
bar