 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
TheGood
Joined: 30 Jul 2007 Posts: 11
|
Posted: Mon Sep 01, 2008 2:26 am Post subject: Using IniRead to read multiple keys |
|
|
| OK, so, I'm trying to read values from a section in an ini file which could have an arbitrary number of keys with arbitrary names. Is there a way to use the IniRead function without knowing the key name? My guess is no, since the Key parameter is not optional, but maybe there's wildcards or something allowed. Otherwise I guess I'll just have to parse the stuff out. |
|
| Back to top |
|
 |
poo_noo
Joined: 08 Dec 2006 Posts: 137 Location: Sydney Australia
|
Posted: Mon Sep 01, 2008 2:58 am Post subject: |
|
|
http://www.autohotkey.com/forum/viewtopic.php?t=24302
http://www.autohotkey.com/forum/viewtopic.php?t=21346
The above should help. I have apps that read keys with multiple sections.
| Code: | ;############# Read variables from INI file ################################################
; adapted from http://www.autohotkey.com/forum/viewtopic.php?t=21346
; adapted from http://www.autohotkey.com/forum/viewtopic.php?t=24302
; set the INI location
; read the INI file
IfNotExist,%sharedfolder%\ahk_config.ini
local_inifile = %A_MyDocuments%\AutoHotkey\ahk_config.ini
Else
local_inifile = %sharedfolder%\ahk_config.ini
;local_inifile = %A_MyDocuments%\AutoHotkey\ahk_config.ini
initializeini(){
global
local key
inisections:=0
loop,read,%local_inifile%
{
if regexmatch(A_Loopreadline,"\[(\w+)]")
{
inisections+= 1
section%inisections%:=regexreplace(A_loopreadline,"(\[)(\w+)(])","$2")
section%inisections%_keys:=0
}
else if regexmatch(A_LoopReadLine,"(\w+)=(.*)")
{
section%inisections%_keys+= 1
key:=section%inisections%_keys
section%inisections%_key%key%:=regexreplace(A_LoopReadLine,"(\w+)=(.*)","$1")
}
}
}
loadini(){
global
local sec,var
loop,%inisections%
{
sec:=A_index
loop,% section%a_index%_keys
{
var:=section%sec%_key%A_index%
iniread,%var%,%local_inifile%,% section%sec%,% section%sec%_key%A_index%
}
}
}
; read the variables from the ahk_config.ini file by calling the following functions
initializeini()
loadini() |
Ini file looks like this
| Code: | [site_details]
mybap=server02
myPrinter=server102\LPSiips
mybackupServer=server201\AHK\
|
_________________ Paul O |
|
| Back to top |
|
 |
TheGood
Joined: 30 Jul 2007 Posts: 11
|
Posted: Mon Sep 01, 2008 3:08 am Post subject: |
|
|
Thanks!
Although I already wrote a quick and dirty script to extract what I want.
But your way is much cleaner! |
|
| Back to top |
|
 |
poo_noo
Joined: 08 Dec 2006 Posts: 137 Location: Sydney Australia
|
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|