Sign in to follow this  
Followers 0
Damein

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

3 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

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

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
Sign in to follow this  
Followers 0