Hello,
How i can sort INI File and retrieve the sections according to values which in it.
This INI File:
[MySection 1]
pos=2
[MySection 2]
pos=1
[MySection 3]
pos=5
[MySection 4]
pos=3
[MySection 5]
pos=4
The desired result should be as follows:
[MySection 2]
[MySection 1]
[MySection 4]
[MySection 5]
[MySection 3]
Sort INI FILE Topic is solved
Re: Sort INI FILE Topic is solved
Hallo,
try:
try:
Code: Select all
INI =
(
[MySection 1]
pos=2
[MySection 2]
pos=1
[MySection 3]
pos=5
[MySection 4]
pos=3
[MySection 5]
pos=4
)
Loop, Parse,% (StrReplace(INI, "`npos"), INI:=""), `n
IF RegExMatch(A_LoopField, "([^=]+)=(.*)", M)
INI .= M2 M1 "`n"
Sort, INI, N
MsgBox,% INI := RegExReplace(INI, "`nm)^\d+")
Last edited by Rohwedder on 29 Nov 2022, 02:42, edited 1 time in total.
Re: Sort INI FILE
You can also use initools lib
Code: Select all
Array2INI(INI2Array(input_ini), output_ini) ;this will sort and remove comments
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory
Re: Sort INI FILE
Thanks. Your library will be very useful to me..Xeo786 wrote: ↑29 Nov 2022, 04:07You can also use initools libCode: Select all
Array2INI(INI2Array(input_ini), output_ini) ;this will sort and remove comments
Re: Sort INI FILE
Hi @HiSoKa,
if it's possible that the pos key won't always immediately follow the section header I'd prefer the following:
if it's possible that the pos key won't always immediately follow the section header I'd prefer the following:
Code: Select all
#NoEnv
/* INI
[MySection 1]
pos=2
[MySection 2]
pos=1
[MySection 3]
pos=5
[MySection 4]
pos=3
[MySection 5]
pos=4
[]
*/
IniFile := A_ScriptFullPath
IniRead, Sections, %IniFile%
Sorted := ""
For Each, Section In StrSplit(Sections, "`n") {
IniRead, Pos, %IniFile%, %Section%, Pos
Sorted .= (Pos != "ERROR") ? Pos . Section . "`n" : ""
}
Sort, Sorted, N
Sorted := RegExReplace(Trim(Sorted, "`n"), "`nm)^\d+")
MsgBox, %Sorted%
Re: Sort INI FILE
yes, pos key don't always immediately follow the section header,
And Your code more readable for me ,, Thanks you so much @just me
And Your code more readable for me ,, Thanks you so much @just me