To download NI software, including the products shown below, visit ni.com/downloads.
Overview
This example VI shows how to read an ini configuration file and extract all sections, keys, and values from it.
Description
This example will programmatically read an ini cofiguration file and extract all sections, keys, and values from it. Each element will be stored as a string in one of three different arrays, respectively: "sections", "keys", or "values" array.
Requirements
Steps to Implement or Execute Code
NOTE: If there are keys in the ini file without values, then these empty strings will not be added to the "values" array. All arrays are created to ignore empty strings.
For more information on ini files, please read here: http://en.wikipedia.org/wiki/INI_file
Additional Information or References
VI Snippet
**This document has been updated to meet the current required format for the NI Code Exchange.**
Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.
The code is a solid starting point, but it has a significant limitation. Based on the three output arrays — one containing the section names, another the key names, and the third the corresponding values — there is no way to directly map sections to their associated key-value pairs. Specifically, the number of keys per section is not preserved, which could become an issue if there's a need to accurately reconstruct the original structure of the .ini
file.
As a possible solution, I suggest changing the sections array to a 2-D array, where each row includes both the section name and the number of keys it contains. This would make it much easier to associate each section with its corresponding keys and values. While this is not the only solution — nor necessarily the best — it is effective and addresses the core problem.