anony10

IniRenameSection without ereasing data?

6 posts in this topic

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? ::ermm:

(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")

Share this post


Link to post
Share on other sites



anony10,

 

IniRenameSection would work, but that erases everything from the section

Only 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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Apparently I can't read... I feel so dumb, thank you M23, answering my stupid questions as usual :P

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?

Share this post


Link to post
Share on other sites

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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Yes I see now, thank you very much once again. :)

Share this post


Link to post
Share on other sites

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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now