To curb the growth of spaces when adding/removing records, the following can be done user end, but I think less cost if in-house:
The wish is for the IniWrite function when writing a value, to check for the next character in the writeloc.
If it is a space, replace it with a null.
Thanks.
Space Growth in Ini Files
Space Growth in Ini Files
itros "ylbbub eht tuO kaerB" a ni kcuts m'I pleH
Re: Space Growth in Ini Files
As it turned out, just a simple solution required:
Code: Select all
IniSpaceCleaner(IniFile)
{
; https://autohotkey.com/boards/viewtopic.php?f=13&t=26556&p=124630#p124630
retVal := 0, temp := "", e := ""
Thread, NoTimers
try
{
FileRead, retVal, %IniFile%
retVal := RegExReplace(retVal, "m) +$", " ") ;m multilineselect; " +" one or more spaces; $ only at EOL
FileDelete, %Inifile%
sleep, 100
FileAppend, %retVal%, %IniFile%
sleep, 100
}
catch e
{
if (e)
MsgBox, 8208, IniSpaceCleaner, Error with Ini file! `nSpecifically: %e%
}
Thread, NoTimers, false
}
itros "ylbbub eht tuO kaerB" a ni kcuts m'I pleH
Re: Space Growth in Ini Files
i've never noticed space growth, and i utilize iniread/write all the time
can you post a script reproducing the problem first? before offering your solution?
can you post a script reproducing the problem first? before offering your solution?
Re: Space Growth in Ini Files
When the above was posted, the decision was made not to use IniDelete. Can't remember why- perhaps the help didn't provide enough examples- or there were other issues regarding extra spaces in the value field- but recall in using it the ini files got messed up.
So with just IniWrite and IniRead it's convenient to initialize all or most entries in the file with something like:
Values can then be written to the key, but they will always have a trailing space.
In the IniRead docs there's
The value is replaced by the space, but not the trailing space(s) already there.
In hindsight, instead of writing a space to delete, it may just be easier to delete the entire key with IniDelete, (if it works), and rewrite it.
Perhaps there are benefits you see with IniDelete?
So with just IniWrite and IniRead it's convenient to initialize all or most entries in the file with something like:
Code: Select all
IniWrite, %A_Space%, %MyIniName%, Section, Key
In the IniRead docs there's
When the value wants to be deleted again, we must do this again:Default
The value to store in OutputVar if the requested key is not found. If omitted, it defaults to the word ERROR. To store a blank value (empty string), specify %A_Space%.
Code: Select all
IniWrite, %A_Space%, %MyIniName%, Section, Key
In hindsight, instead of writing a space to delete, it may just be easier to delete the entire key with IniDelete, (if it works), and rewrite it.
Perhaps there are benefits you see with IniDelete?
itros "ylbbub eht tuO kaerB" a ni kcuts m'I pleH
Re: Space Growth in Ini Files
The OS preserves trailing spaces in the same way that it preserves line endings and comments, because the trailing space is not part of the value.
An empty value is not the same as a non-existent value, due to IniRead's Default parameter.
Virtually all limitations and quirks of the INI functions come directly from the OS. AutoHotkey does not write to or read the file, or modify the results given by the OS in any way, except:IniRead wrote:The operating system automatically omits leading and trailing spaces/tabs from the retrieved string. To prevent this, enclose the string in single or double quote marks. The outermost set of single or double quote marks is also omitted, but any spaces inside the quote marks are preserved.
- Converting between null-delimited lists (required/returned by the API) and newline-delimited lists.
- If the file does not exist, IniWrite creates the file with a UTF-16 BOM in Unicode builds. It also writes the section header to prevent the OS from inserting an empty line at the top of the file. It does not write anything else to the file.
An empty value is not the same as a non-existent value, due to IniRead's Default parameter.
Who is online
Users browsing this forum: a_bolog and 14 guests