Empty lines at bottom of INI files get deleted

Recommended Posts

DickG 1

DickG 1

I just installed v3.3.14.2 (from v3.3.10.2). I just noticed something really strange: When I try to add a new line at the bottom of an INI, it can't because something is deleting any empty lines at the bottom. I verified that it's only my code that's doing it. But whenever I run a script or compile it, the lines get deleted. Anyone else run into this problem?

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post

Link to post

Share on other sites

DickG 1

DickG 1

Can someone confirm that this is indeed a change in "something"? After further testing, it looks like _FileCountLines() has changed how it works. It used to include ALL lines (including empty lines at bottom). Then I would know if I need to add another blank line. But with v3.3.14.2, it only looks for lines that have text. So I can no longer tell if I have to add another blank line before I add a new record.

I have a lot of scripts that depend on knowing if there is an empty line at the end of an INI section so that I can add a new record. But _FileWriteToLine("Path", $Last_line, "New record", False) would overwrite the last record because it thought that $Last_line was BELOW the last line, not AT the last line. Maybe there's a better way of doing this, but it's been working fine up until v3.3.14.2.

Share this post

Link to post

Share on other sites

mikell 609

mikell 609

Water is right, but if you disagree then you are completely allowed to build your own custom FileCountLines funcThe one from File.au3 is regexp-based so you can use this little variant (try it on your dummy .ini from post #4)

Share this post

Link to post

Share on other sites

DickG 1

DickG 1

Water is right, but if you disagree then you are completely allowed to build your own custom FileCountLines funcThe one from File.au3 is regexp-based so you can use this little variant (try it on your dummy .ini from post #4)

I tried those INI functions in the beginning, but was frusrated by how limited they are. I couldn't do things like insert a record below or above another record, or insert a new section in a specific place in the INI.

So I built my own set of INI functions to deal with the things I wanted it to do.

It can also simulate "nested" folders in records by using tabs (one for each level), then counting the tabs later to tell me which level it's at when building a treeview or listview to show the hierarchy. I can also insert new sections anywhere I want in the INI, move entire sections up and down, and so on.

_FileCountLines() used to count empty lines at the bottom. But no more. So I had modify all my scripts to look for the end of a section and compare it to the "last line". So I had to write my own __FileCountLines() function. It uses _FileRecToArray("INI file", $File_array). Then I set $Last_line = $File_array[0].

My INI UDFs returns $Section_start and $Section_end (as well as the Key and Val for a record) for any section. I can then compare $Section_end to $Last_line. If they are the same, it means the last record is also the last line. But to add a new line to the bottom, I had to have the "pointer" sitting below the last line. Otherwise, it wasn't writing the blank line to the end. Hence, it wasn't adding a new record to the end. So I was losing data without knowing it.

Maybe my need for more power behind manipulating INIs isn't common. But I can do powerful things with it. Like a project manager that shows the "nested" INI sections in a treeview, then shows the files contained in a selected section in a listview to the right, for example.

Anyway, I've accepted that it changed, and tweaked things to get around the problem.

Share this post

Link to post

Share on other sites

BrewManNH 1,037

BrewManNH 1,037

If you're worried about where in the INI file the lines are, you're using the INI file and the functions for them wrong.

The standards for INI files specifies that they are never in any type of order other than SECTION/KEYs in that section/VALUE assigned to that key.

You are using them as flat files, which is fine to do, they're just not INI files when you treat them that way regardless of how you name them. They may look like an INI file, you may format them like one, but how you're using them is not a standardized way.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Share this post

Link to post

Share on other sites

TheSaint 1,354

TheSaint 1,354

Although I'm a big fan of INI files usually (though they can having annoying issues), you would probably be better off using XML in your case.

Either that, or do something like you are doing, and give them a different extension, as an INI file is a specific type of file, and used in a specific manner. You can still use IniRead and IniWrite with whatever extension you use instead of INI ... or just use Array functions.

Some people use CFG or LOG or INF etc ... or make up your own.

P.S. I seem to recall, that guinness wrote some special kind of INI functions or setup ... check Examples for it.

P.S.S. I've been using INI files since Win 3.1 and in those days a blank line got created between sections. Later they (Microsoft) made it so that blank lines got stripped. Some INI commands still strip blank lines, some don't.

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key?Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox(be advised many downloads are not working due to ISP screwup with my storage)

I tried that before, but I had to deal with too many FileOpen() and FileClose() instances. So I abandoned that method.

I wanted a way to write to a file without using FileOpen/Close(). _FileWriteToLine() fit the bill perfectly. But it seems like something changed in v3.3.14.2. It no longer allows empty lines at the bottom. So now I use IniWrite() only if I'm adding a new record to the bottom of the file. Otherwise, I NEED to have records and sections in a specific order for my applications.

Share this post

Link to post

Share on other sites

DickG 1

DickG 1

Although I'm a big fan of INI files usually (though they can having annoying issues), you would probably be better off using XML in your case.

Either that, or do something like you are doing, and give them a different extension, as an INI file is a specific type of file, and used in a specific manner. You can still use IniRead and IniWrite with whatever extension you use instead of INI ... or just use Array functions.

Some people use CFG or LOG or INF etc ... or make up your own.

P.S. I seem to recall, that guinness wrote some special kind of INI functions or setup ... check Examples for it.

P.S.S. I've been using INI files since Win 3.1 and in those days a blank line got created between sections. Later they (Microsoft) made it so that blank lines got stripped. Some INI commands still strip blank lines, some don't.

I could rename them. But it doesn't cause a problem for me to call them "INI" files.

I found that "INI" files were the most effective way (for me, anyway) to deal with a faux flat-file database such as financial records and other types of structured info.

If the standard way of using an INI is locked down somewhere, it will remain frustrating to deal with for me. Using XML would mean I would have to learn that syntax too. It's not structured to be easy to read at the raw file level.

I created apps to replace programs like Quicken and Info Select (which uses their own proprietary database). I could not easily export the data from them. So I got frustrated with dealing with proprietary databases and decided to make my own replacements. They track things like financial records that must be in Date order, sections that must be in a specific order, etc. I also needed a way to insert records between two records (like when adding a financial transaction before or after a certain date). I could not do that with the standard INI functions. But now I can with my own functions that handles non-standard "INI" files.