Add multiple entries to same .ini file category?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
scriptor2016
Posts: 860
Joined: 21 Dec 2015, 02:34

Add multiple entries to same .ini file category?

08 Nov 2020, 14:30

Hi again :)

This is kind of a little follow up to yesterday's question where I was trying to fileappend with multiple line breaks.

I'm trying a little bit of a different approach here, and going with an .ini file to see how it works out.

Here's my sample code:

Code: Select all

iniwrite, %title%, C:\MyInfiFile.ini, INFO, title
iniwrite, %clipboard%, C:\MyInfiFile.ini, INFO, stuff

and the resulting .ini file looks like this:

[INFO]
title=MyTitle
stuff=apples


my question is, how do I add more entries to the same 'stuff' category? For example, I would want the resulting .ini file to look like this:

[INFO]
title=MyTitle
stuff=apples
stuff=oranges
stuff=bananas
stuff=cucumbers


as it is right now, the code just keeps overwriting the stuff category with each iniwrite command.
User avatar
mikeyww
Posts: 26931
Joined: 09 Sep 2014, 18:38

Re: Add multiple entries to same .ini file category?

08 Nov 2020, 15:43

The idea of an INI file is that, within any given section (e.g., "info"), every key (e.g., "stuff") is unique. You could name the keys, as "stuff1", "stuff2", etc. if that helps.
scriptor2016
Posts: 860
Joined: 21 Dec 2015, 02:34

Re: Add multiple entries to same .ini file category?

08 Nov 2020, 21:01

yes it does help, thank-you.

Here's what I did to make it happen:

Code: Select all

increment=1 ;this is the very first line in the entire code

execute: (this is the g-label for a button which was assigned earlier in the script)
iniwrite, %title%, C:\MyInfiFile.ini, INFO, title
iniwrite, %clipboard%, C:\MyInfiFile.ini, INFO, stuff_%increment%
increment++
and now, the .ini file is looking like this:

title=MyTitle
stuff_1=apples

stuff_2=oranges

stuff_3=bananas

stuff_4=cucumbers


which seems to work quite nicely!

the problem now is, why is it writing a blank line in between each "stuff" entry. Is there a way to remove those blank lines when it writes the next entry?
User avatar
mikeyww
Posts: 26931
Joined: 09 Sep 2014, 18:38

Re: Add multiple entries to same .ini file category?

08 Nov 2020, 22:11

You are sending the Clipboard's contents, so it presumably contains a carriage return or line feed. If you delete that (and delete your existing INI file, too), you should be in good shape.

Code: Select all

ini = C:\MyInfiFile.ini
FileRecycle, %ini%
IniWrite, ThisTitle, %ini%, INFO, title
Clipboard = abc`n
IniWrite, % Trim(Clipboard, "`r`n"), %ini%, INFO, stuff_1
IniWrite, % Trim(Clipboard, "`r`n"), %ini%, INFO, stuff_2
Run, %ini%
Microsoft Excel adds CRLF to copied cells.
scriptor2016
Posts: 860
Joined: 21 Dec 2015, 02:34

Re: Add multiple entries to same .ini file category?

08 Nov 2020, 22:52

woohoo, thanks mikeyww. This is working now. I'm trying a few different things here so I might be building on it.. I might be back again looking for more advice on this one. Thanks again :)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: OrangeCat, Rohwedder, roysubs and 317 guests