anony10 Posted April 6, 2015 Share Posted April 6, 2015 Hi I would like to use the IniRenameSection command without it erasing everything in that given section. $openLearningDb = fileopen("test.txt", 1) ;open new database $desiredLines = iniRead("test123.ini", "base", "importx", "") $countEntries = _filecountlines("test.txt") if $desiredLines > $countEntries then msgbox(0, "", "there is less lines than what we need!") for $i = 1 to $desiredLines - $countEntries $importingArray = inireadsection("test123.ini", $i) ;import the desired lines _arraydisplay($importingArray) filewriteline($openLearningDb, $importingArray[2][1] & "|" & $importingArray[1][1]) ;write to the file inidelete("test123.ini", $i) ;delete them Next ;when done msgbox(0, "imported new words", "new words") endif Every time the difference between $desiredLines and $countEntries is at least 1, this loop should run which is supposed to read the ini file, the first section (simply called [1]), write it into an other file and then delete this section from the ini file. This works flawlessly however the next time the difference is 1, there obviously will be no 1, as the lowest entry will be at least 2. I was thinking of using stringreplace for renaming, but that is way too brute for hundreds - if not thousands - of entries, and too much work. IniRenameSection would work, but that erases everything from the section, and saving everything first into a .tmp file or something and then rewriting it is not a way to go in my opinion. Any other ideas? (I had this for renaming, but obviously this ends up erasing everything in the end) ;~ $getSectionNames = inireadsectionnames("test123.ini") ;get the no of sections ;~ for $i = 2 to $getSectionNames[0] ;loop through them and rename them to 1, 2, 3 etc ;~ inirenamesection("test123.ini", $getSectionNames[$i], $i - 1, 1) ;~ next ;_FileReadToArray2D("test.txt", $aArray, "|") ;load it to a 2D array ;~ msgbox(0, "sections renamed", "sections renamed") Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 6, 2015 Moderators Share Posted April 6, 2015 anony10, IniRenameSection would work, but that erases everything from the sectionOnly if you set the "flag" parameter to 1 - if you leave it at 0 then the section is simply renamed as long as there is no existing section of that name: #include <MsgBoxConstants.au3> $sIniName = "Test.ini" $sIniData = "[1]" & @CRLF & "key1=value1" & @CRLF & "[2]" & @CRLF & "key2=value2" & @CRLF & "[3]" & @CRLF & "key3=value3" FileWrite($sIniName, $sIniData) IniRenameSection($sIniName, "2", "4") ; Default value for "flag" is 0 $sIniNew = FileRead($sIniName) MsgBox($MB_SYSTEMMODAL, "New Ini", $sIniNew)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 Link to comment Share on other sites More sharing options...
anony10 Posted April 6, 2015 Author Share Posted April 6, 2015 Apparently I can't read... I feel so dumb, thank you M23, answering my stupid questions as usual It does say in the reference (under the flag) however that "1 - Overwrite "new section". This will erase any existing keys in "new section"" so I either dont know how to english, or thats a typo? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 6, 2015 Moderators Share Posted April 6, 2015 anony10,If you set the flag to 0 then the rename will fail if the section name already exists - setting it to 1 means that it will replace an already existing section. Try running the script above again, but rename section [2] to section [3] - first with the flag at 0 and then 1. Make sure you delete the inifile after each run. 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 Link to comment Share on other sites More sharing options...
anony10 Posted April 6, 2015 Author Share Posted April 6, 2015 Yes I see now, thank you very much once again. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 6, 2015 Moderators Share Posted April 6, 2015 anony10,My pleasure. 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 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