Jump to content

Cleanest way to remove an entry in an INI and re-assign all other keys?


Go to solution Solved by Damein,

Recommended Posts

So let's say we have an INI setup like so:

[Test]
0=Empty
1=Test1|0||1|1
2=Test2|1|1|1
3=Test3|0|0|0

And we wan't to remove entry 2. What would be the best way to remove that, and then change #3 to be labeled as #2 and do it in a fashion to if I had say hundred's of entries it would still accomplish this.

Edited by Damein

MCR.jpg?t=1286371579

Most recent sig. I made

Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic

Link to comment
Share on other sites

Read #3, set #2 to the value of #3, delete #3.

Using InIRead, IniWrite, InIDelete.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • Solution

Thank's water, I found a way to do it before reading this but essentially I think it's the same.

Func _RemoveMovie()
    $Index = ControlListView($MainGui, "Movie Database", $MovieListView,"GetSelected")
    $ReadControl = _GUICtrlListView_GetItemText($MovieListView, 0+$Index)
    $MovieCount = IniReadSection(@ScriptDir & "/Data/Movie Database.ini", $CurrentCategory)
    For $i = 0 To $MovieCount[0][0]
        $SplitData = StringSplit($MovieCount[$i][1], "|")
        If $SplitData[1] = $ReadControl Then
            IniDelete(@ScriptDir & "/Data/Movie DataBase.ini", $CurrentCategory, $i -1)
            ExitLoop
        EndIf
    Next

    $MovieCount = IniReadSection(@ScriptDir & "/Data/Movie Database.ini", $CurrentCategory)
    For $i = 1 To $MovieCount[0][0]
        $OldData[$i] = IniRead(@ScriptDir & "/Data/Movie Database.ini", $CurrentCategory, $i, "NA")
        If $OldData[$i] = "NA" Then
            $OldData[$i] = IniRead(@ScriptDir & "/Data/Movie Database.ini", $CurrentCategory, $i+1, "NA")
            IniDelete(@ScriptDir & "/Data/Movie Database.ini", $CurrentCategory, $i+1)
        EndIf
        IniDelete(@ScriptDir & "/Data/Movie Database.ini", $CurrentCategory, $i)
        $Count = $i
    Next

    For $i = 1 To $Count - 1
        IniWrite(@ScriptDir & "/Data/Movie Database.ini", $CurrentCategory, $i, $OldData[$i])
    Next
EndFunc

MCR.jpg?t=1286371579

Most recent sig. I made

Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...