AutoIt
; ; creates a dictionary with the prefix $dict_ (in the Global scope) ; each $dict_ variable corresponds to a unique ini section, mapping it's keys to values ; returns the number of dictionaries created (aka the number of sections in the ini file) ; ; USE WITH CAUTION ; variable name creation will not work if section headers have characters other ; than letters, numbers, or the _ character. However, spaces are removed. func _ini_to_dict($fname_ini_config) local $ini_list = IniReadSectionNames( $fname_ini_config ) if @error then MsgBox(0, "Error", "Could not read ini file: " & $fname_ini_config ) return -1 endif local $i, $j local $name, $dict local $slots local $key, $val for $i=1 to $ini_list[0] $slots = IniReadSection( $fname_ini_config, $ini_list[$i] ) $name = "dict_" & StringStripWS($ini_list[$i],8) $dict = ObjCreate("Scripting.Dictionary") for $j = 1 to $slots[0][0] $key = $slots[$j][0] $val = $slots[$j][1] $dict.Add( $key, $val ) next Assign($name, $dict, 2) next return $i-1 endfunc ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; example of how to run Dim $count Dim $key, $val $count = _ini_to_dict( "c:\Whatever.ini" ) MsgBox(0,"count", $count) if -1 = $count then; an error occured exit endif ; change Whatever to a ini section header for $key in $dict_Whatever $val = $dict_Whatever.Item($key) MsgBox(0, $key, $val ) next
Edited by jftuga, 24 May 2006 - 03:08 PM.





