The design was intentional. The point of it is: If you know what section and keyname you want, you can specify it.READPROFILESTRING ("file name", "section", "key")
If you do not know what section, or what key you specify "" and you get a list of all of them in the file. This would be used if for instance you had an .ini file with an undetermined number of parameters, but you needed to make sure that they were all read and set in some way. You could ask for the list of all sections, then ask for the list of all keys and churn your way through them all. I have a piece of code I swiped that does just that (I think I swiped it off this board even):
Below is an example of how to walk through all of the sections & keys in an INI file. If you have trouble with copy/paste, then send me an e-mail here:
Marty.List "at" Janus.com
$Sections = ReadProfileString("$CollectionPath\$NextFile", "", "")
If $Sections = "" Shell '%ComSpec% /C Ren "$CollectionPath\$NextFile" "*.BAD"' EndIf
While $Sections
$Sections = "$Sections" + Chr(10)
$LineFeed = InStr("$Sections", Chr(10))
$NextSection = SubStr("$Sections", 1, $LineFeed-1)
$Sections = SubStr("$Sections", $LineFeed+1, Len("$Sections")-$LineFeed)
While $NextSection
If $Verbose $Status = "Processing $NextFile [$NextSection]" GoSub "_ShowStatus" EndIf
$Keys = ReadProfileString("$CollectionPath\$NextFile", "$NextSection", "")
If $Keys = "" Shell '%ComSpec% /C Ren "$CollectionPath\$NextFile" "*.BAD"' EndIf
While $Keys
$Keys = "$Keys" + Chr(10)
$LineFeed = InStr("$Keys", Chr(10))
$NextKey = SubStr("$Keys", 1, $LineFeed-1)
$Keys = SubStr("$Keys", $LineFeed+1, Len("$Keys")-$LineFeed)
While $NextKey
If $Verbose $Status = "Processing $NextFile [$NextSection] $NextKey" GoSub "_ShowStatus" EndIf
$LoginRecord = ReadProfileString("$CollectionPath\$NextFile", "$NextSection", "$NextKey")
$ResultCode = WriteProfileString("$MasterLogFile", "$NextSection", "$NextKey", "$LoginRecord")
If $ResultCode <> 0
$Message = "WARNING: Collector.KiX failed, WriteProfileString($MasterLogFile, $NextSection, $NextKey, $LoginRecord) returned $ResultCode"
GoSub "_Notify"
GoTo "_Complete"
EndIf
$LineFeed = InStr("$Keys", Chr(10))
$NextKey = SubStr("$Keys", 1, $LineFeed-1)
$Keys = SubStr("$Keys", $LineFeed+1, Len("$Keys")-$LineFeed)
Loop
Loop
$LineFeed = InStr("$Sections", Chr(10))
$NextSection = SubStr("$Sections", 1, $LineFeed-1)
$Sections = SubStr("$Sections", $LineFeed+1, Len("$Sections")-$LineFeed)
Loop
Loop
------------------
K Torkelson
Sys Admin Analyst
ktorkelson@providentfunding.com