INI file

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by Cole SWE (talk | contribs) at 16:31, 12 August 2007 (→‎Differences). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

An initialization file, or INI file, is a configuration file that contains configuration data (i.e. idiom terms) for Microsoft Windows based applications.

Starting with Windows 95, the INI file format was superseded but not entirely replaced by a registry database in Microsoft operating systems. Recently, XML became a popular choice for encoding configuration, as well as other kinds of data for many applications, but INI format is still in use.

Although made popular by Windows, INI files can be used on any system thanks to their flexibility. They allow a program to store configuration data, which can then be easily parsed and changed.

File Format

A typical INI file might look like this:

[section1]

; some comment on section1
var1 = abc
var2 = 451
 
[section2]

; another comment
var1 = 123
var2 = dfg

Format

This describes the elements of the INI file format:

  • Sections: Section declarations start with '[' and end with ']' as in [section1] and [section2] above. And sections start with section declarations.
  • Parameters: The "var1 = abc" above is an example of a parameter (also known as an item). Parameters are made up of a key ('var1'), equals sign ('='), and a value ('abc').
  • Comments: All the lines starting with a semicolon (';') are assumed to be comments, and are ignored.

Differences

The format of INI files is not well defined. Many programs interpret their structure differently than the basic structure that was defined in the above example. The following is a basic list of some of the differences:

  • Quoted values: The Microsoft Windows implementation (see: GetPrivateProfileString in MSDN) will remove quotation marks (apostrophes and double-quotes) that surround INI file values.
  • Comments: Programs like Samba accept either ';' or '#' as comments. Comments can be added after parameters with several formats.
  • Backslashes: Adding a backslash '\' allows you to continue the value from one line to another. Some formats also allow various escapes with a '\', such as '\n' for newline.
  • Duplicate parameters: Most of the time, you can't have two parameters with the same name in one section. Therefore one can say that parameters are local to the section. Although this behavior can vary between implementations, it is advisable to stick with this rule.
  • Duplicate sections: If you have more than one section with the same name then the last section overrides the previous one. (Some implementations will merge them if they have different keys.)
  • Some implementations allow ":" in place of "=" and/or skipping the surrounding spaces.

See also

External links