Jump to content

Recommended Posts

Posted (edited)

I just need a confirmation (or rejection ;)) that this is some kind of a bug in IniReadSection - When i trying to rename the section and it's does not contain keys (just an empty [section]), the rename fails. But IniDelete for example working fine, the section been deleted.

So i supose this is a bug in IniRenameSection... or not? ^_^

Edit: typo.

Edited by MrCreatoR

 

  Reveal hidden contents

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

  • Moderators
Posted (edited)

MrCreatoR,

I get the same thing - IniRenameSection fails if the Section has no keys - IniDelete works as expected.

Playing around I found that you can rename the Section thus:

$sIni = @ScriptDir & "\test.ini"
IniDelete($sIni, "Section 2")
IniWriteSection($sIni, "Section Two", "")

But it does screw up the original order. :-)

M23

Edit: Vista x32 HP SP1

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted

same results here on XP SP3

Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.

Posted (edited)

  Quote

But it does screw up the original order

Exactly.

The solution is this:

Func _IniRenameSection($sIni_File, $sSection, $sNew_Section, $iFlag=0)
    If $iFlag = 1 Then IniDelete($sIni_File, $sNew_Section)
    
    Local $sIni_Content = FileRead($sIni_File)
    If @error Then Return SetError(1, 0, 0)
    
    If $iFlag = 0 And StringRegExp($sIni_Content, "(rn|)[" & $sNew_Section & "](rn|)") Then Return SetError(2, 0, 0)
    
    $sIni_Content = StringRegExpReplace($sIni_Content, "[" & $sSection & "]", "[" & $sNew_Section & "]")
    
    Local $iEncoding = FileGetEncoding($sIni_File)
    Local $hIni_Open = FileOpen($sIni_File, $iEncoding + 2)
    FileWrite($hIni_Open, $sIni_Content)
    Return FileClose($hIni_Open)
EndFunc

But i think the original function should do it.

Edited by MrCreatoR

 

  Reveal hidden contents

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

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
  • Recently Browsing   0 members

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