Jump to content

Read complete INI section


ozbob
 Share

Recommended Posts

I would like to read all the keys and values from one particular INI Section. With the option INIREAD I cannot see how to do this since you need to specify the key within the section.

But I don't know the key so I want to read the entire SECTION without specifying the key(s).

Link to comment
Share on other sites

I would like to read all the keys and values from one particular INI Section. With the option INIREAD I cannot see how to do this since you need to specify the key within the section.

But I don't know the key so I want to read the entire SECTION without specifying the key(s).

<{POST_SNAPBACK}>

Hello look on the Autoit Helpfiles ! :lmao:

$sFile=@SCRIPTDIR & '\Test.ini'
$spam6=IniRead($sFile, 'spam', 'spam', 'Read this ini')
$spam=InputBox("DirtyBanditos", "Please enter your Message", $spam6)
iniwrite($sFile, 'spam', 'spam', $spam)
Link to comment
Share on other sites

$spam6=IniRead($sFile, 'spam', 'spam', 'Read this ini')

In this line you specify SPAM twice:

1. For the section

2. For the key

My problem is that I know which SECTION to read but I do NOT know the KEY name.....I want to know which keys there are and how many.

Any suggestions.....

Link to comment
Share on other sites

I'm not remember, maybe someone made and posted similar UDF. Here is my variant:

Dim $str = ""
$a = _IniEnumKeys("wincmd.ini", "left")
For $i = 1 to $a[0]
    $str = $str & $a[$i] & @CR
Next
MsgBox (0, "Num keys=" & $a[0], $str)

Func _IniEnumKeys($sIni, $sSection)
    Local $aKeys[1], $iKeyCnt = 1
    $aKeys[0] = 0
    $hIniFile = FileOpen($sIni, 0)
    While 1
        $sLine = FileReadLine($hIniFile)
        If @error = -1 Then 
            FileClose($hIniFile)
            Return $aKeys
        Endif
        If StringInStr($sLine, "[" & $sSection & "]") Then Exitloop
    Wend
    While 1
        $sLine = FileReadLine($hIniFile)
        If @error = -1 Then Exitloop
        $sLine = StringStripWS($sLine, 3)
        If StringLeft($sLine, 1) == "[" and StringRight($sLine, 1) == "]" Then Exitloop
        $iEqPos = StringInStr($sLine, "=")
        If $iEqPos and not (StringLeft($sLine, 1) == ";") Then
            $iKeyCnt = $iKeyCnt + 1
            ReDim $aKeys[$iKeyCnt]
            $aKeys[$iKeyCnt-1] = StringLeft($sLine, $iEqPos-1)
        Endif
    Wend
    FileClose($hIniFile)
    $aKeys[0] = $iKeyCnt - 1
    Return $aKeys
EndFunc
Link to comment
Share on other sites

Weird, I remember reading this thread, but it had no bearing what-so-ever on my post I made in the developer's private forum. There's an API call to get this information, it just hasn't been added to AutoIt yet. After the next stable release (103), I'll submit something to Jon for the new beta's that will do this.

And before anybody asks, the function isn't useable with DllCall(), it uses double-NULL terminated strings with NULL delimiters.

Link to comment
Share on other sites

$a = _IniEnumKeys("wincmd.ini", "left")

...the great TCommander! :lmao:

Weird, I remember reading this thread, but it had no bearing what-so-ever on my post I made in the developer's private forum.  There's an API call to get this information, it just hasn't been added to AutoIt yet.  After the next stable release (103), I'll submit something to Jon for the new beta's that will do this.

And before anybody asks, the function isn't useable with DllCall(), it uses double-NULL terminated strings with NULL delimiters.

<{POST_SNAPBACK}>

By the way, it would be very good.
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...