Ini (.ini)

Background

    Configuration file format.
    Composed of sections.
    Associates string keys to string values.
    Stores configurations for operating systems and software.
    Plain text format.

Import and Export

  • Import["file.ini"] returns a representation of an Ini file as an Association.
  • Import["file","Ini"] returns a representation of a file as an Ini file.
  • Import["file.ini",elem] returns the specified data representation of an Ini file.
  • Import["file",{"Ini",elem}] returns the specified data representation of a file.
  • Export["file.ini",expr] exports expr as a Ini file.

Elements

  • General Import elements:
  • "Elements" list of elements and options available in this file
    "Rules"full list of rules for each element and option
    "Options"list of rules for options, properties and settings
  • Data representation elements:
  • "Data"data as an association
    "DataRules"data as a list of rules
    "AnnotatedData"data as a list of sections as rules, and comments as strings
  • The Ini format exports elements of an association or a list.
  • "Ini" treats an association as a list of sections. The keys specify the section names; the values specify the elements of a section as associations. Expressions are converted to their input form string representation.
  • "Ini" accepts lists containing a mixture of rules and strings. Rules are exported as sections; strings are exported as commented lines.
  • A commented line starts with ";".

Examples

Basic Examples  (6)

Export an association as a section with properties:

In[1]:=
Click for copyable input
Out[1]=

Create a file:

In[1]:=
Click for copyable input

Add a section and few properties to it:

In[2]:=
Click for copyable input

Import it as an Ini file:

In[3]:=
Click for copyable input
Out[3]=

Create a file:

In[1]:=
Click for copyable input

Write properties and comments to it:

In[2]:=
Click for copyable input

Import the data only, as an Association:

In[3]:=
Click for copyable input
Out[3]=

Import the data and the comment:

In[4]:=
Click for copyable input
Out[4]=

Whitespace characters are not trimmed:

In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
Out[2]=

Sections must start with the character "[" and finish with "]":

In[1]:=
Click for copyable input
Out[1]=

Commented lines must start with the character ";":

In[2]:=
Click for copyable input
Out[2]=

Arbitrary expressions are converted to strings using InputForm:

In[1]:=
Click for copyable input
Out[1]=

See Also

"PHPIni"  "JavaProperties"  "CSV"  "TSV"  "ApacheLog"  "Text"

Introduced in 2017
(11.1)