Jump to content
Sign in to follow this  

Extended INIDelete

Recommended Posts

You can now delete whole INI sections with my INIDelete function.

And when you specify a key to delete, my function executes the built-in function.

Examples at the bottom.


- Added some error checking

The function:

Func _INIDelete($gINIFile, $gINISection, $gINIKey = "")
   Local $i
   Local $CurLine
   Local $INISize
   Local $mINIKey
   Local $INIArray
   Local $mINISect
   Local $INIContent
   Local $OpenINI_write
   If $gINIKey <> "" Then
      Local $Err
      $Err = INIDelete($gINIFile, $gINISection, $gINIKey)
      Return $Err
   $mINIKey = 0
   $mINISect = 0
   If NOT FileExists($gINIFile) Then
      Return 0
      $INISize = FileGetSize($gINIFile)
      $INIContent = FileRead($gINIFile, $INISize)
      If NOT StringInStr($INIContent, @LF) Then
         Return 0
         $INIArray = StringSplit(StringStripCR($INIContent), @LF)
      $INIContent = 0
   $OpenINI_write = FileOpen($gINIFile, 2)
   For $i = 1 To $INIArray[0]
      $CurLine = StringStripWS($INIArray[$i], 7)
      If StringLeft($CurLine, StringLen($gINISection) + 2) = "[" & $gINISection & "]" _
         OR StringLeft($CurLine, StringLen($gINISection) + 4) = "[ " & $gINISection & " ]" Then
            $mINISect = 1
      ElseIf StringLeft($CurLine, 1) = "[" Then
         $mINISect = 0
      If NOT $mINISect Then
         If $CurLine <> "" Then FileWriteLine($OpenINI_write, $INIArray[$i])
   $INIArray = 0
   Return 1

Example 1:

;Deletes section "Settings" from Test.ini
_INIDelete(@ScriptDir & "\Test.ini", "Settings")

Example 2:

;Deletes section "Settings" from Test.ini
_INIDelete(@ScriptDir & "\Test.ini", "Settings", "")

Example 3:

;Deletes key "Width" from section "Settings" from Test.ini
_INIDelete(@ScriptDir & "\Test.ini", "Settings", "Width")
Edited by SlimShady

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...