Lemures Posted October 13, 2006 Posted October 13, 2006 I'm very tired and simply dont feel like doing this at the moment. Anybody have any tricks up their sleeve for doing the following? I have a .ini file with a lot of sections, and I need to reorganize the .ini file so that the sections and their keys are put in it alphabetically in descending order. I have another program that reads through the sections, but when they are out of order it gets frustrating. Any ideas?
JSThePatriot Posted October 13, 2006 Posted October 13, 2006 I'm very tired and simply dont feel like doing this at the moment. Anybody have any tricks up their sleeve for doing the following?I have a .ini file with a lot of sections, and I need to reorganize the .ini file so that the sections and their keys are put in it alphabetically in descending order. I have another program that reads through the sections, but when they are out of order it gets frustrating. Any ideas?I would recommend you use the INIReadSectionNames() to create an array of all the section names. Use _ArraySort() (standard include) to sort them how you want them. Use INIWrite() with INIReadSection() using the values in the INIReadSectionNames() array you previously created, and write a new sorted INI file. Delete the old file, and rename the new file with a FileMove().JS AutoIt Links File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out. ComputerGetInfo UDF's Updated! 11-23-2006 External Links Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)
Lemures Posted October 13, 2006 Author Posted October 13, 2006 I would recommend you use the INIReadSectionNames() to create an array of all the section names. Use _ArraySort() (standard include) to sort them how you want them. Use INIWrite() with INIReadSection() using the values in the INIReadSectionNames() array you previously created, and write a new sorted INI file. Delete the old file, and rename the new file with a FileMove().JSsounds like a plan. as soon as i wake up tomorrow morning, I will do it Thanks!By the way, the program is for EVE online, if anybody plays that, ive got some pretty need programs ive made that make working the market ingame a LOT easier.
JSThePatriot Posted October 13, 2006 Posted October 13, 2006 sounds like a plan. as soon as i wake up tomorrow morning, I will do it Thanks!By the way, the program is for EVE online, if anybody plays that, ive got some pretty need programs ive made that make working the market ingame a LOT easier.No problem. Get some sleep, and no doubt tomorrow you will be fired up and ready to roll! I am happy I was able to help you in the right direction.JS AutoIt Links File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out. ComputerGetInfo UDF's Updated! 11-23-2006 External Links Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)
Moderators SmOke_N Posted October 13, 2006 Moderators Posted October 13, 2006 (edited) This seemed it could be useful, so I gave it a go: [zorder] b=1 d=3 c=4 a=g [corder] g=6 k=3 d=2 z=3 a=2 b=3 Func _IniSort($hIni) Local $aIRSN = IniReadSectionNames($hIni) If Not IsArray($aIRSN) Then Return SetError(1, 0, 0) _ArraySort($aIRSN, 0, 1) Local $aKey, $sHold For $iCC = 1 To UBound($aIRSN) - 1 Local $aIRS = IniReadSection($hIni, $aIRSN[$iCC]) If Not IsArray($aIRS) Then ContinueLoop For $xCC = 1 To $aIRS[0][0] $aKey &= $aIRS[$xCC][0] & Chr(1) Next If $aKey Then $aKey = StringSplit(StringTrimRight($aKey, 1), Chr(1)) _ArraySort($aKey, 0, 1) $sHold &= '[' & $aIRSN[$iCC] & ']' & @CRLF For $aCC = 1 To UBound($aKey) - 1 $sHold &= $aKey[$aCC] & '=' & IniRead($hIni, $aIRSN[$iCC], $aKey[$aCC], 'blahblah') & @CRLF Next $aKey = '' EndIf Next If $sHold Then $sHold = StringTrimRight($sHold, 2) FileClose(FileOpen($hIni, 2)) FileWrite($hIni, $sHold) Return 1 EndIf Return SetError(1, 0, 0) EndFuncoÝ÷ ØGb´èXy¨jº^Would have saved alot of time if I had looked Edited October 13, 2006 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
1905russell Posted October 13, 2006 Posted October 13, 2006 I would recommend you use the INIReadSectionNames() to create an array of all the section names. Use _ArraySort() (standard include) to sort them how you want them. Use INIWrite() with INIReadSection() using the values in the INIReadSectionNames() array you previously created, and write a new sorted INI file. Delete the old file, and rename the new file with a FileMove().JSI will try this too. Thanks for the guidance.
JSThePatriot Posted October 13, 2006 Posted October 13, 2006 I will try this too. Thanks for the guidance.NP I hope it works out for you.JS AutoIt Links File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out. ComputerGetInfo UDF's Updated! 11-23-2006 External Links Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)
Valik Posted October 13, 2006 Posted October 13, 2006 This should be trivial. Start by renaming the source file to move it out of the way. Now read the section names from the source with IniReadSectionNames() and use _ArraySort() on it. Now you know which order to process the sections in. Now iterate that array using InIReadSection() to read the section and use _ArraySort() on that 2D array to sort it (by key). Now use IniWriteSection() (*Beta-only*) to write the section to a new file. Lastly, delete the source file. Be aware that IniReadSection() strips any non key=value lines so comments or invalid syntax will be stripped. It should be about half the code Smoke shows.
Moderators SmOke_N Posted October 13, 2006 Moderators Posted October 13, 2006 I'm guessing everyone skipped over the last example here:http://www.autoitscript.com/forum/index.ph...st&p=251323 Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
ChrisL Posted October 13, 2006 Posted October 13, 2006 This is one I did some time ago if it helps. expandcollapse popup#include <GuiConstants.au3> #include <Array.au3> GuiCreate("INI Tidy", 392, 166,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS), $WS_EX_ACCEPTFILES ) $Input_1 = GuiCtrlCreateInput("", 20, 30, 220, 20) GUICtrlSetState ( -1, $GUI_DROPACCEPTED ) $Browse = GuiCtrlCreateButton("Browse", 270, 30, 90, 20) $Sortit = GuiCtrlCreateButton("Sort my god damn messy ini file out", 100, 60, 260, 30) $Label = GuiCtrlCreateLabel("", 20, 110, 340, 30) $tick = GUICtrlCreateCheckbox ("", 65, 70, 20,20) GuiCtrlSetState (-1 ,$GUI_CHECKED) GuiCtrlCreateLabel("Sort Section", 20, 58, 80, 15) GuiCtrlCreateLabel("Names", 20, 72, 40, 15) GuiSetState() While 1 $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Browse $inifile = FileOpenDialog ("Select the ini file", @scriptdir, "(*.ini)") GUICtrlSetData ($Input_1, $iniFile) Case $msg = $Sortit If GuiCtrlRead ($Input_1) = "" Then MsgBox (0,"Error","No ini file selected") Elseif FileExists(GuiCtrlRead ($Input_1)) = 0 then MsgBox (0,"Error","Can not open ini file") Else If StringRight (GuiCtrlRead ($Input_1),3) <> "ini" then MsgBox (0,"Error", "File must be an ini file") Else SortNow(GuiCtrlRead ($Input_1)) Endif EndIf Case Else ;;; EndSelect WEnd Exit Func SortNow($ini) If FileExists ($ini &".tmp") then FileDelete($ini & ".tmp") $aSArray = IniReadSectionNames ($ini) If GuictrlRead ($tick) = 1 then _ArraySort( $aSArray,0,1) For $x = 1 to Ubound ($aSArray) -1 $String = "" $avArray = IniReadSection ($ini, $aSArray[$x]) guiCtrlSetData ($Label,"Checking " & $aSArray[$x]) For $i = 1 to Ubound ($avArray) -1 $string = $String & $avArray[$i][0] & "=" & $avArray[$i][1] & Chr(01) Next $aString = StringSplit ($String, Chr(01)) _ArraySort( $aString,0,1) $File = FileOPen ($ini & ".tmp",1) FileWriteLine ($File, "[" & $aSArray[$x] & "]") For $i = 1 to Ubound ($aString) -1 FileWriteLine ($File, $aString[$i]) guiCtrlSetData ($Label,"Writing " & $aString[$i]) Next FileWriteLine ($File, @CRLF & @CRLF) FileClose ($File) Next guiCtrlSetData ($Label,"Sorted!") Sleep (1000) FileMove ($ini, Stringtrimright ($ini, 4) & "Backup" & @MDAY & @Mon & @year & "_" & @Hour & @Min & ".ini") FileMove ($ini & ".tmp", $ini) MsgBox(0,"Done","Old file has been renamed " & Stringtrimright ($ini, 4) & "Backup" & @MDAY & @Mon & @year & "_" & @Hour & @Min &".ini") Run ("notepad " & $ini) EndFunc [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire
gcue Posted March 27, 2013 Posted March 27, 2013 This seemed it could be useful, so I gave it a go: [autoit]Func _IniSort($hIni) Local $aIRSN = IniReadSectionNames($hIni) If Not IsArray($aIRSN) Then Return SetError(1, 0, 0) _ArraySort($aIRSN, 0, 1) Local $aKey, $sHold For $iCC = 1 To UBound($aIRSN) - 1 Local $aIRS = IniReadSection($hIni, $aIRSN[$iCC]) If Not IsArray($aIRS) Then ContinueLoop For $xCC = 1 To $aIRS[0][0] $aKey &= $aIRS[$xCC][0] & Chr(1) Next If $aKey Then $aKey = StringSplit(StringTrimRight($aKey, 1), Chr(1)) _ArraySort($aKey, 0, 1) $sHold &= '[' & $aIRSN[$iCC] & ']' & @CRLF For $aCC = 1 To UBound($aKey) - 1 $sHold &= $aKey[$aCC] & '=' & IniRead($hIni, $aIRSN[$iCC], $aKey[$aCC], 'blahblah') & @CRLF Next $aKey = '' EndIf Next If $sHold Then $sHold = StringTrimRight($sHold, 2) FileClose(FileOpen($hIni, 2)) FileWrite($hIni, $sHold) Return 1 EndIf Return SetError(1, 0, 0) EndFunc
Moderators Melba23 Posted March 27, 2013 Moderators Posted March 27, 2013 gcue,Did you really mean to post in thread that was over 6 1/2 years old? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
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