Page 1 of 1

Ini file help

Posted: 20 Sep 2021, 08:03
by Plantim
Hello,

I want to :
- my script checks if an ini file exist
- if not, then create one
- if exist, then check if value exist, don't edit it. If value doesn't exist, then create it

Code: Select all

IniRead, active1 , FollowSettings.ini, Personnages, active1
IniWrite, % active1 , FollowSettings.ini, Personnages, active1
IniWrite, % active2 , FollowSettings.ini, Personnages, active2
With the code below, active1 is setting "ERROR" (because value don't exist the first time)
If i don't set "iniRead", it will erase any value evrytime...

I want, for example, checking value, if it find "active1 = %anyvalue%", don't edit it. If Active1 doesn't exist, create it but with empy value

Thank you for help, sorry for bad english

Re: Ini file help  Topic is solved

Posted: 20 Sep 2021, 08:40
by mikeyww
After you read the value, check to see if it is ERROR. If so, then you can write the new value. An alternative is below.

Code: Select all

ini    := StrReplace(A_ScriptFullPath, ".ahk", ".ini")
active1 = a
active2 = b
section = Personnages
Loop, 2 {
 IniRead ,   active%A_Index%, %ini%, %section%, active%A_Index%, % active%A_Index%
 IniWrite, % active%A_Index%, %ini%, %section%, active%A_Index%
}
MsgBox, 64, Results, active1 = %active1%`nactive2 = %active2%
Adjust as needed. This does not store an empty value, but you could do that if needed. There is typically not much value in doing that.

Re: Ini file help

Posted: 20 Sep 2021, 11:10
by Plantim
Thank you !
I just added %A_Space% after every "IniRead"

Like this

Code: Select all

IniRead, active1 , FollowSettings.ini, Personnages, active1, %A_Space%
Now it works like i wanted !

Thank you very much