Howto: Enumerate INI Sections/Keys/Values from an INI file

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
neil9090
Posts: 64
Joined: 28 Jun 2014 00:09

Howto: Enumerate INI Sections/Keys/Values from an INI file

Post by neil9090 »

This is how you can enumerate INI sections/keys and key values.

I found in a forum item how to get the first section in the INI, which was good, but then I found out the that returned getkey value also included any other section names. This was also true to keys which means you can also get all of the values as well.
The values returned by getkey are separated by chr(0) but also includes chr(0) at the beginning thus the trim commands.

e.g. example.ini
[Section1]
Key1=Key1Value
[Section2]
Key2=Key2Value

Simple but if you didn't know that of the section2 name this would be a problem

I couldn't find an existing topic so just thought I would post it.

Code: Select all

	// Enumerate INI Sections/Keys/Values

	$GEN_Ini = self("path")."\".self("base").".ini"; // ini file
//	$GEN_Ini adjust accordingly to suit needs

	$tempstring = "";
	$Sections = trim(getkey("", "", $GEN_Ini),chr(0));
		
	foreach($section, $Sections, chr(0))
	{
		$Keys = trim(getkey("", $section, $GEN_Ini),chr(0));
		foreach($key, $Keys, chr(0))
		{
			$tempstring = $tempstring . "Section : " . $section . "." . $key .
				"=>" . getkey($key, $section, $GEN_Ini) .
				"<crlf>";
		}		
	}
        // output found values for demonstration purposes...
	msg $tempstring; // no scrollbar
	text $tempstring; // popup box
	echo $tempstring;
Last edited by neil9090 on 21 Jul 2014 22:22, edited 1 time in total.

bdeshi
Posts: 4249
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612 / Dhaka
Contact:

Re: Howto: Enumerate INI Sections/Keys/Values from an INI fi

Post by bdeshi »

Nice! :appl:
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

klownboy
Posts: 4140
Joined: 28 Feb 2012 19:27

Re: Howto: Enumerate INI Sections/Keys/Values from an INI fi

Post by klownboy »

Yes, very nice and I just learned something. "msg" doesn't provide an vertical scroll bar for a long message so I suppose we should use text or echo which does for cases like this. 8)
Windows 11, 23H2 Build 22631.3447 at 100% 2560x1440

SkyFrontier
Posts: 2341
Joined: 04 Jan 2010 14:27
Location: Pasárgada (eu vou!)

Re: Howto: Enumerate INI Sections/Keys/Values from an INI fi

Post by SkyFrontier »

$GEN_Ini = "<xydata>\<xyini>"; // ini file
seems to be a safer choice, guys.
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: Howto: Enumerate INI Sections/Keys/Values from an INI fi

Post by TheQwerty »

SkyFrontier wrote:$GEN_Ini = "<xydata>\<xyini>"; // ini file
seems to be a safer choice, guys.
Only if you actually want XYplorer's INI file - neil9090's reading in an INI file that has the same path and name as the script file.
klownboy wrote:we should use text or echo which does for cases like this. 8)
Echo should be synonymous with msg so it wouldn't show scrollbars either. ;)

bdeshi
Posts: 4249
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612 / Dhaka
Contact:

Re: Howto: Enumerate INI Sections/Keys/Values from an INI fi

Post by bdeshi »

Actually echo does show a scrollbar. Blame genetics. (msg not being the same as it's little brother)

Anyways, it makes more sense for the result to be used as some kind of script input, instead of displaying it...
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

SkyFrontier
Posts: 2341
Joined: 04 Jan 2010 14:27
Location: Pasárgada (eu vou!)

Re: Howto: Enumerate INI Sections/Keys/Values from an INI fi

Post by SkyFrontier »

Thanks for the note, TQ!
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...

klownboy
Posts: 4140
Joined: 28 Feb 2012 19:27

Re: Howto: Enumerate INI Sections/Keys/Values from an INI fi

Post by klownboy »

TheQwerty wrote:Echo should be synonymous with msg so it wouldn't show scrollbars either
I too have a scroll bar with echo but none with msg. I wonder if it's expected and possibly a bug. Certainly no biggie, typically you wouldn't use msg for a case like this anyway or as Sammay mentioned you'd have the results returned to the script.
Windows 11, 23H2 Build 22631.3447 at 100% 2560x1440

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: Howto: Enumerate INI Sections/Keys/Values from an INI fi

Post by TheQwerty »

klownboy wrote:
TheQwerty wrote:Echo should be synonymous with msg so it wouldn't show scrollbars either
I too have a scroll bar with echo but none with msg. I wonder if it's expected and possibly a bug. Certainly no biggie, typically you wouldn't use msg for a case like this anyway or as Sammay mentioned you'd have the results returned to the script.
I don't think it's a bug, just my mistake. I always thought they were one and the same but indeed the documentation calls echo msg's smaller brother so the differences are correct.

Post Reply