If you look at it on Windows, there is an ini file called
I would appreciate an example of how to read and write it.
I have not used Windows for a long time. Only when it gets warm here, I will open one.
An INI file is just a text-file, right?
So, why not parsing the file, and store the values in something like a dictionary.
To start, I would read the file line by line. Skip the lines that start with a #
or a ;
since INI files support those lines as comment-lines. Blank lines can be skipped, for obvious reasons.
When a line starts with a [ and ends with a ], it is considered a section, as shown in THIS article.
Other lines should have at least 1 = character. Characters before the = symbol would be the key of a key-value pair. The characters after the = symbol would be the value.
So, my approach would be to create a Dictionary
object.
Each DictionaryEntry would be a section, of the INI file. Where the Key is the name of the section. The Value would be another Dictionary, holding the key-value pairs of that section.
Another approach is to store the values in a (SQLite) database, with the fields: Section, Key, Value. That makes it easier to find the values later on.
To write the values to an INI file, is also straight forward.
Just go through the Section dictionary. Write each Key to the INI file, surrounded with the [ and ] characters.
For each section, write the Key-Value pairs, as subscribed in the INI format documentation.
For better legibility, you could add an EndOfLine
after each section.
We still have a WindowsIniMBS class in MBS Xojo Plugins in case you use our plugins.
I think people may not be reading the second post, so I’ll pick one link from that thread