d0n Posted July 20, 2009 Share Posted July 20, 2009 is there a way to sort ini files, i only found functions to sort GUI stuff my file is similar to this, and i want to be able to sort them ascending or decending Me=123 Jon=412 Dave=12 what kind of functions should i be looking at to achieve this? Link to comment Share on other sites More sharing options...
GEOSoft Posted July 20, 2009 Share Posted July 20, 2009 _IniSort() http://dundats.mvps.org/AutoIt/udf_code.aspx?udf=ini George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
Rishav Posted July 20, 2009 Share Posted July 20, 2009 that answers your question anyway, but you can also put the ini data in an array, then sort the array and finally write back into the ini file. Link to comment Share on other sites More sharing options...
d0n Posted July 20, 2009 Author Share Posted July 20, 2009 I got this error when using the _IniSortSectionByValue() C:\Program Files\AutoIt3\Include\ini.au3 (101) : ==> Incorrect number of parameters in function call.: _ArraySort($sArray, $s_Order, 1, 0, 2, 1) ^ ERROR ->12:29:29 AutoIT3.exe ended.rc:1 +>12:29:30 AutoIt3Wrapper Finished >Exit code: 1 Time: 5.079 expandcollapse popup#Include <File.au3> #include <ini.au3> $Log = @ScriptDir&"\Logger.ini" If FileExists($Log) = 0 Then _FileCreate($Log) IniWrite($Log, "Name", "####", "0") EndIf $sStr = FileRead(FileOpenDialog("Select the Log file", @Scriptdir&"\","Text (*.txt)")) ;Dim $sStr = FileRead(@scriptdir & "\test.txt") Dim $sPatt = '(?i)\[[^]]*\]\s*(.*?)(?:hit|slashe?)s?.*?for\s*(\d+)' Dim $aLines = StringSplit($sStr, @CRLF, 1) Global $P1_Total = 0 For $i = 1 To $aLines[0] Local $aMatch = StringRegExp($aLines[$i], $sPatt, 1) If UBound($aMatch) = 2 Then $a = IniReadSection($Log, "Name") IniDelete($Log, "Name", "####") $aMatch[0] = StringTrimRight($aMatch[0],1) For $size=1 To $a[0][0] If $a[$size][0] = $aMatch[0] Then $dmg = IniRead($Log, "Name", $aMatch[0], "0") $dmg = $dmg + $aMatch[1] IniWrite($Log, "Name", $aMatch[0], $dmg) exitloop EndIf Next If $size > $a[0][0] then IniWrite($Log, "Name", $aMatch[0], $aMatch[1]) EndIf Next _IniSortSectionByValue($Log, "Name", 0) Link to comment Share on other sites More sharing options...
GEOSoft Posted July 20, 2009 Share Posted July 20, 2009 I got this error when using the _IniSortSectionByValue() expandcollapse popup#Include <File.au3> #include <ini.au3> $Log = @ScriptDir&"\Logger.ini" If FileExists($Log) = 0 Then _FileCreate($Log) IniWrite($Log, "Name", "####", "0") EndIf $sStr = FileRead(FileOpenDialog("Select the Log file", @Scriptdir&"\","Text (*.txt)")) ;Dim $sStr = FileRead(@scriptdir & "\test.txt") Dim $sPatt = '(?i)\[[^]]*\]\s*(.*?)(?:hit|slashe?)s?.*?for\s*(\d+)' Dim $aLines = StringSplit($sStr, @CRLF, 1) Global $P1_Total = 0 For $i = 1 To $aLines[0] Local $aMatch = StringRegExp($aLines[$i], $sPatt, 1) If UBound($aMatch) = 2 Then $a = IniReadSection($Log, "Name") IniDelete($Log, "Name", "####") $aMatch[0] = StringTrimRight($aMatch[0],1) For $size=1 To $a[0][0] If $a[$size][0] = $aMatch[0] Then $dmg = IniRead($Log, "Name", $aMatch[0], "0") $dmg = $dmg + $aMatch[1] IniWrite($Log, "Name", $aMatch[0], $dmg) exitloop EndIf Next If $size > $a[0][0] then IniWrite($Log, "Name", $aMatch[0], $aMatch[1]) EndIf Next _IniSortSectionByValue($Log, "Name", 0) I'll fix that in a few minutes. I forgot to change the upload the last time. I'll send you a PM when it's ready which will be right after I re-test it. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
d0n Posted July 20, 2009 Author Share Posted July 20, 2009 Thank you! Link to comment Share on other sites More sharing options...
GEOSoft Posted July 20, 2009 Share Posted July 20, 2009 Now I remember why I didn't upload the new version, I shave a couple more functions to add to it. Change the defective line to _ArraySort($sArray, $s_Order, 1, 0, 2) and it should work. I'm still doing more testing before I do the upload. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
d0n Posted July 20, 2009 Author Share Posted July 20, 2009 No errors this time but it still didn't sort the ini file The code #include <ini.au3> $Log = @ScriptDir&"\Logger.ini" _IniSortSectionByValue($Log, "Name") The Ini file [Name] Don=123 Jon=321 Jack=23 Link to comment Share on other sites More sharing options...
GEOSoft Posted July 20, 2009 Share Posted July 20, 2009 No errors this time but it still didn't sort the ini file The code #include <ini.au3> $Log = @ScriptDir&"\Logger.ini" _IniSortSectionByValue($Log, "Name") The Ini file [Name] Don=123 Jon=321 Jack=23 That would be becuase I gave you the wrong code. This works for me _ArraySort($sArray, $s_Order, 1, 0, 1) George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
d0n Posted July 20, 2009 Author Share Posted July 20, 2009 ok, it works but i have a question right now its sorting it a different way than i expected Don=123 Jon=321 Jack=23 sorts into Don=123 Jack=23 Jon=321 but i was hoping that it would turn into Jack=23 Don=123 Jon=321 Since 23<123<321 Link to comment Share on other sites More sharing options...
Authenticity Posted July 20, 2009 Share Posted July 20, 2009 #include <Array.au3> Dim $sFile = @ScriptDir & '\file.ini' Dim $aINI = IniReadSection($sFile, 'name') _ArrayDisplay($aINI) For $i = 1 To $aINI[0][0] For $j = 1 To $aINI[0][0]-$i If Int($aINI[$j+1][1]) < Int($aINI[$j][1]) Then Local $sTemp = $aINI[$j][1] $aINI[$j][1] = $aINI[$j+1][1] $aINI[$j+1][1] = $sTemp EndIf Next Next _ArrayDisplay($aINI) Link to comment Share on other sites More sharing options...
d0n Posted July 20, 2009 Author Share Posted July 20, 2009 that sorts the value in col1 but the name corresponding to the value doesn't shift with it after sorting ending up with a wrong value for some names Link to comment Share on other sites More sharing options...
GEOSoft Posted July 20, 2009 Share Posted July 20, 2009 (edited) #include <Array.au3> Dim $sFile = @ScriptDir & '\file.ini' Dim $aINI = IniReadSection($sFile, 'name') _ArrayDisplay($aINI) For $i = 1 To $aINI[0][0] For $j = 1 To $aINI[0][0]-$i If Int($aINI[$j+1][1]) < Int($aINI[$j][1]) Then Local $sTemp = $aINI[$j][1] $aINI[$j][1] = $aINI[$j+1][1] $aINI[$j+1][1] = $sTemp EndIf Next Next _ArrayDisplay($aINI) I knew that was out there someplace. I'm going to have to modify that function to handle numeric values one of these days. I'll put it on the list of things to do tomorrow and we know the story about that day. Edited July 20, 2009 by GEOSoft George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
Authenticity Posted July 20, 2009 Share Posted July 20, 2009 @d0n: A little bit modification is required to swap names as well, the concept is similar. Just store the element of the array you want to replace, move the next element the current element and put the stored value in the next element. About 4 more lines of code. I'm working on a quick sort with a recursive function all done using Execute() function to get the value of a variant array to an arbitrary dimensional length but it trick is to find a way to store it this way. More testing. Link to comment Share on other sites More sharing options...
d0n Posted July 22, 2009 Author Share Posted July 22, 2009 Worked with 3 more lines , thanks for the help #include <Array.au3> Dim $sFile = @ScriptDir & '\RevLogger.ini' Dim $aINI = IniReadSection($sFile, 'name') _ArrayDisplay($aINI) For $i = 1 To $aINI[0][0] For $j = 1 To $aINI[0][0]-$i If Int($aINI[$j+1][1]) > Int($aINI[$j][1]) Then Local $sTemp = $aINI[$j][1] $aINI[$j][1] = $aINI[$j+1][1] $aINI[$j+1][1] = $sTemp Local $sTemp1 = $aINI[$j][0] $aINI[$j][0] = $aINI[$j+1][0] $aINI[$j+1][0] = $sTemp1 EndIf Next Next _ArrayDisplay($aINI) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now