Ini (.ini)
Background & Context
-
- Configuration file format.
- Composed of sections.
- Associates string keys to string values.
- Stores configurations for operating systems and software.
- Plain text format.
Import & 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.
- See the following reference pages for full general information:
-
Import, Export import from or export to a file CloudImport, CloudExport import from or export to a cloud object ImportString, ExportString import from or export to a string ImportByteArray, ExportByteArray import from or export to a byte array
Import Elements
- General Import elements:
-
"Elements" list of elements and options available in this file "Summary" summary of the file "Rules" list of rules for all available elements - 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:
ExportString[<|"webservers" -> <|"tomcat.server.1" -> "host1", "tomcat.server.2" -> "host2"|>|>, "Ini"]file = CreateFile[];Add a section and few properties to it:
WriteString[
file, "
[login]
user=root
password=12345"];Import[file, "Ini"]file = CreateFile[];Write properties and comments to it:
WriteString[file, "
;An example of a Windows boot.ini
[boot loader]
timeout=40
default=multi(0)disk(0)rdisk(0)partition(1)\\WINDOWS
[operating systems]
multi(0)disk(0)rdisk(0)partition(1)\\WINDOWS=\"Microsoft Windows XP Professional\" /fastdetect
"];Import the data only, as an Association:
Import[file, "Ini"]Import the data and the comment:
Import[file, {"Ini", "AnnotatedData"}]Whitespace characters are not trimmed:
ImportString[" key = value ", "Ini"]ImportString["; comment starting with spaces", {"Ini", "AnnotatedData"}]Sections must start with the character "[" and finish with "]":
ImportString[" [section]", "Ini"]Commented lines must start with the character ";":
ImportString[" ; comments", "Ini"]Arbitrary expressions are converted to strings using InputForm:
ExportString[<|"Section" -> <|"quantity" -> Quantity[1, "Hours"]|>|>, "Ini"]Related Guides
History
Introduced in 2017 (11.1)