;IniSectionGet Fuction ;Get All sections names from Said file and store in said array IniSectionGet(File,Array) { i = 0 ;Index used for array element number Loop, Read, %File% { StringLeft, L, A_LoopReadLine, 1 ;Possible Section name, so check right side If L = [ { StringRight, R, A_LoopReadLine, 1 ;If its a right bracket Section found If R = ] { i++ ;Econt = Element Contents ECont = %A_LoopReadLine% StringTrimLeft, ECont, ECont, 1 StringTrimRight, ECont, ECont, 1 %Array%%i% = %ECont% } } } %Array%0 = %i% }
The above funtion syntax is:
IniSectionGet(File,Array)
File is the Ini file to be checked
Array is the name of the array for info to be stored in.
Array0 will contain how many sections were found in the file and the Array Elements will contain the names of the sections.
Hardcore testing welcome ...as well as optimization (Laszlo???)
Sect = Section2 Array = SampleArray File = %A_ScriptDir%\TestIni.ini IniKeyGet(File,Sect,Array) F9::Reload ;IniKeyGet Function ;Gets all key names from said section of said file and store in said array ;Array0 stores how many elements are in said array. IniKeyGet(File,Sect,Array) { i = 0 LineNum = 0 Loop, Read, %File% { LineNum ++ Section = [%Sect%] If A_LoopReadLine = %Section% { LineNum++ Loop { FileReadLine, LineCont, %File%, %LineNum% ;Check is line may be a section, not a key name StringLeft, LL, LineCont, 1 If LL = [ { ;Declare Array0 Value %Array%0 = %i% ListVars Return } ;Line not a key If LineCont Not Contains = { LineNum++ Continue } i++ StringSplit, KeyName, LineCont, = %Array%%i% = %KeyName1% LineNum++ } } } }
Syntax for IniKeyGet
IniKeyGet(File,Section,Array)
File To anylize
Section to anylize
Name of array to be created
Array0 will contain the amount of keys in the section and each element will contain the name of the key
Again, Testing, comments, feedback, and optimization all very welcome
Edit: New code submitted, less tested
Edit: KeyGet Fn futher optimized. From 68 line to 45 lines