Jump to content
Sign in to follow this  
bcording

Get Ini Sections And Section Entries

Recommended Posts

bcording

The first function will fill the passed array with all the section names of the given INI file. The second function will fill the passed array with all the entries of the given section of the given INI file. Both set @Error to 1 if they succeed.

Func GetSections(Byref $DataArray, $INIFile)
    Local $File, $Line
    Local $Sections

    $File = FileOpen($INIFile,0)
    If $File = -1 Then Return

    While 1
        $Line = FileReadLine($File)
        If @error = -1 Then ExitLoop
        $Line = StringStripWS($Line,3)
        If StringLeft($Line,1) = "[" And StringRight($Line,1) = "]" then
            $Line = StringMid($Line,2,StringLen($Line)-2)
            $Sections = $Sections & $Line & @LF
        EndIF
    Wend

    FileClose($File)
    If StringLen($Sections) = 0 Then Return
    $DataArray = StringSplit(StringTrimRight($Sections,1),@LF)
    SetError(1)
EndFunc

Func GetSectionEntries(Byref $DataArray, $Section, $INIFile)
    Local $File, $Line
    Local $Entries

    $File = FileOpen($INIFile,0)
    If $File = -1 Then Return

    While 1
        $Line = FileReadLine($File)
        If @error = -1 Then ExitLoop
        $Line = StringStripWS($Line,3)
        If $Line = "[" & $Section & "]" then
            While 1
                $Line = FileReadLine($File)
                If @error = -1 Then ExitLoop
                $Line = StringStripWS($Line,3)
                If StringLeft($Line,1) = "[" then ExitLoop(2)
                If StringLeft($Line,1) <> ";" And StringLen($Line) <> 0 then
                    $Entries = $Entries & $Line & @LF
                EndIF
            Wend
        EndIF
    Wend

    FileClose($File)
    If StringLen($Entries) = 0 Then Return
    $DataArray = StringSplit(StringTrimRight($Entries,1),@LF)
    SetError(1)
EndFunc

Share this post


Link to post
Share on other sites
Nutster

Shouldn't they set @Error to 1 if they fail?


David Nuttall
Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius

AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...

Share this post


Link to post
Share on other sites
ezzetabi

it seens that Bcoding like writing If @error Then

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  

×