|Download Help (Windows Only)|
Use the Configuration File VIs to read and create standard Windows configuration settings (.ini) files and to write platform-specific data, such as paths, in a platform-independent format so that you can use the files these VIs generate across multiple platforms. The Configuration File VIs do not use a standard file format for configuration files. While you can use the Configuration File VIs on any platform to read and write files created by the VIs, you cannot use the Configuration File VIs to create or modify configuration files in a Mac OS X or Linux format.
Refer to the labview\examples\file\config.llb for examples of using the Configuration File VIs.
|Note The standard extension for Windows configuration settings files is .ini, but the Configuration File VIs work with files with any extension, provided the content is in the correct format.|
A standard Windows configuration settings file is a specific format for storing data in a text file. You can programmatically access data within the .ini file easily because it follows a specific format.
For example, consider a configuration settings file with the following contents:
You can use the Configuration File VIs to read this data, as shown in the following block diagram. This VI uses the Read Key VI to read the key named Value from the section called Data. This VI works regardless of how the file changes, provided the file remains in the Windows configuration settings file format.
Windows configuration settings files are text files divided into named sections. Brackets enclose each section name. Every section name in a file must be unique. The sections contain key/value pairs separated by an equal sign (=). Within each section, every key name must be unique. The key name represents a configuration preference, and the value name represents the setting for that preference. The following example shows the arrangement of the file:
Use the following data types with Configuration File VIs for the value portion of the key parameter:
To use the Configuration File VIs, you must format each line of text in an .ini file correctly. A line must either be empty or contain a section name, a key-value pair, or a comment.
Use the following guidelines to format lines with section names:
Use the following guidelines to format lines with key-value pairs:
|Note If values begin or end with whitespace characters, you must put the values in quotation marks. LabVIEW removes the quotation marks when a VI returns the value.|
Configuration File VIs ignore lines without section names or value-key pairs during a read operation, and they preserve lines without section names or value-key pairs during a write operation.
When VIs write to a configuration file, they place quotation marks around any string or path data. LabVIEW also supports single quotes around values in .ini files.
The accepted comment notation for configuration files is a semicolon, which can indicate that the text following the semicolon is a comment. A semicolon at the beginning of a line indicates a comment. A semicolon in a section name, numeric value, or Boolean value also indicates a comment. However, a semicolon in a string value name does not indicate a comment.
If you include a semicolon as the first character of a key name, LabVIEW does not return a key name or value because the configuration files do not support a semicolon as the first character of a key name. If you include a semicolon at any other place in the key name besides as the first character, LabVIEW returns the key name with the semicolon.
The following table provides examples of how the Configuration File VIs read section names in .ini files.
|Example text in .ini file||Section name|
|[ sec with spaces ]||sec with spaces|
The following table provides examples of how the Configuration File VIs read key-value pairs in .ini files.
|Example text in .ini file||Key name||Value|
|keyname = 12.3 ;comm||keyname||12.3|
|key name6=" mystring6"||key name6||mystring6|
|keyname8 = mystring8||keyname8||mystring8|
|keyname9 = " mystring9 "||keyname9||mystring9|
|#keyname13 = mystring13||#keyname13||mystring13|
|Note Because the Read Key VI is a polymorphic VI, it acts differently in certain instances. For example, for the keyname = 12.3 ;comm key-value pair, the String instance returns a string value of 12.3;comm and the Double instance returns a numeric of 12.3 for the value output.|
The Configuration File VIs can read and write raw or escaped string data. The VIs read and write raw data byte-for-byte, without converting the data to ASCII. In converted, or escaped, strings LabVIEW stores any non-displayable text characters in the configuration settings file with the equivalent hexadecimal escape codes, such as \0D for a carriage return. In addition, LabVIEW stores backslash characters in the configuration settings file as double backslashes, such as \\ for \. Set the read raw string? or write raw string? inputs of the Configuration File VIs to TRUE for raw data and to FALSE for escaped data.
LabVIEW stores path data in a platform-independent format, the standard Linux format for paths, in .ini files. The VIs interpret the absolute path /c/temp/data.dat stored in a configuration settings file as follows:
The VIs interpret the relative path temp/data.dat as follows: