Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

IniRenameSection without ereasing data?

$
0
0

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

Viewing all articles
Browse latest Browse all 12506

Trending Articles