getkey for all keys in a section
getkey for all keys in a section
Hi there,
How would I use getkey (or would I use something else instead) to get ALL of the keys in a section?
Cheers.
How would I use getkey (or would I use something else instead) to get ALL of the keys in a section?
Cheers.
Windows 10 Pro 22H2
Re: getkey for all keys in a section
readfile()
regexmatch() / regexreplace()
foreach loop to do whatever you want with each entry
regexmatch() / regexreplace()
foreach loop to do whatever you want with each entry
One of my scripts helped you out? Please donate via Paypal
Re: getkey for all keys in a section
Depends on the format of your ini, I guess.kiwichick wrote:How would I use getkey (or would I use something else instead) to get ALL of the keys in a section?
You can e.g.:
- read in the ini file to $ini
- for each $line in in $ini,
--- if $line contains "[mysection]", start work
--- $ARRAY = $ARRAY . $line . "<crlf>";
--- if $line contains "[", stop working
(additionally, you can check if "[" is at pos. 1)
- for each $line in in $ARRAY, msg $line;
- for each $line in in $ARRAY, gettoken($value, 2, "="); msg $value;
If your ini has a counter like
Code: Select all
[Toolbars]
Count=11
1_Date=20110601 0807
2_Date=20110617 0833
...
...
Code: Select all
while($loop <= $SectionCount){
$array = $array . getkey($loop . "_Date", "Toolbars", $INIname) . "|";
$loop++;
}
-
- Site Admin
- Posts: 63451
- Joined: 22 May 2004 16:48
- Location: Win8.1, Win10, Win11, all @100%
- Contact:
Re: getkey for all keys in a section
Actually it is possible by leaving the key empty:
Code: Select all
// in $ListOfKeysInSection the keys are separated by NULL characters:
$ListOfKeysInSection = getkey("", "General", "<xydata>\xyplorer.ini");
text replace($ListOfKeysInSection, chr(0), "<crlf>");
FAQ | XY News RSS | XY Bluesky
Re: getkey for all keys in a section
Hard to know if it's not mentioned in the help file *g*Actually it is possible by leaving the key empty:
One of my scripts helped you out? Please donate via Paypal
-
- Site Admin
- Posts: 63451
- Joined: 22 May 2004 16:48
- Location: Win8.1, Win10, Win11, all @100%
- Contact:
Re: getkey for all keys in a section
It's a known Windows standard (when you know the API). 

FAQ | XY News RSS | XY Bluesky
Re: getkey for all keys in a section
Thanks Don, The only problem with it is that it lists only the keys, not the values of the keys which is what I'm after. Sorry I didn't make that obvious in my original post but I thought that would have been a given since that is what the getkey command does - "Gets the value of a configuration key" (quote Help file), not the key itself.admin wrote:Actually it is possible by leaving the key empty:Code: Select all
// in $ListOfKeysInSection the keys are separated by NULL characters: $ListOfKeysInSection = getkey("", "General", "<xydata>\xyplorer.ini"); text replace($ListOfKeysInSection, chr(0), "<crlf>");
Cheers.
Stefan - Thanks, I'll go check your suggestions out now.
Windows 10 Pro 22H2
-
- Site Admin
- Posts: 63451
- Joined: 22 May 2004 16:48
- Location: Win8.1, Win10, Win11, all @100%
- Contact:
Re: getkey for all keys in a section
Well, once you have the keys it's easy, no?
FAQ | XY News RSS | XY Bluesky
Re: getkey for all keys in a section
For those of you who do this all time maybe. But for me, who still spends forever figuring out stuff, then no it's not.admin wrote:Well, once you have the keys it's easy, no?
Windows 10 Pro 22H2
Re: getkey for all keys in a section
How it goes? Did you worked it out?kiwichick wrote: Stefan - Thanks, I'll go check your suggestions out now.
Here is a ready to use script to read/get a whole section content from a INI file_
Code: Select all
////XYplorer script to read INI file and get a whole section content
//The Code
$INI = readfile("<xydata>\xyplorer.ini");
$do=0;
$out="";
foreach( $line, $INI, "<crlf>"){
$c = substr($line, 0, 1);
if($c == "[" ){$section=$line; $do=1;}
if($do==1){
if($line != ""){
$out = $out . $line . "<crlf>";
}else{
text $out; // in var $out you have the whole section content
msg "Section $section done, continue with next section?",1;
//writefile("%temp%\xyptestexport\$section.txt", $out);
$do=0;
$out="";
}
}
}
msg "Done";
As result you get here several prompts, but you can change the script to do with the result what you want.
.
[Register]
Name=John Doe
Code=xxxx-xxxx-xxxx-xxxx-xxxx-xxxx-xxxx-xxxx
dc=1
---------------------------
XYplorer
---------------------------
Section [Register] done, continue with next section?
---------------------------
OK Abbrechen
---------------------------
[General]
LastVer=13.00.0008
WinW=900
WinH=600
---------------------------
XYplorer
---------------------------
Section [General] done, continue with next section?
---------------------------
OK Abbrechen
---------------------------
and so on...
Last edited by TheQwerty on 22 Oct 2013 23:33, edited 1 time in total.
Reason: Removed registration information - just in case.
Reason: Removed registration information - just in case.
-
- Posts: 4319
- Joined: 28 Feb 2012 19:27
- Location: Windows 11, 24H2 Build 26100.3915 at 100% 2560x1440
Re: getkey for all keys in a section
I hope that reg key you're displaying is bogus or I'd delete it... 

Re: getkey for all keys in a section
Hi Stefan, Thanks for that. I gave up in the end because I just couldn't figure it out. What I want is to get keys from ONE section only. And it to be only the VALUES of the keys.
So from:
[General]
LastVer=13.10.0109
WinW=900
WinH=661
WinX=165
WinY=3
WinZ=41128
WinState=2
WinStatePrev=2
WinOnTray=0
SplitPos=218
SplitPosXDP=748
I want:
13.10.0109
900
661
165
3
41128
2
2
0
218
748
But between your code and what highend posted too, I should be able to do something now. Thanks again.
So from:
[General]
LastVer=13.10.0109
WinW=900
WinH=661
WinX=165
WinY=3
WinZ=41128
WinState=2
WinStatePrev=2
WinOnTray=0
SplitPos=218
SplitPosXDP=748
I want:
13.10.0109
900
661
165
3
41128
2
2
0
218
748
But between your code and what highend posted too, I should be able to do something now. Thanks again.
Windows 10 Pro 22H2
Re: getkey for all keys in a section
buddies... of course that was neither my name nor a valid key
just for your issue "get keys from ONE section only. And only the VALUES of the keys.".
(ROT13 "encrypted" do not put the joy from you.
There are online tools to "decrypt", or I have for sure posted a ROT13 script somewhere?!?!?)
.



Just in case you got stuck, here is a example codekiwichick wrote:What I want is to get keys from ONE section only. And it to be only the VALUES of the keys.
just for your issue "get keys from ONE section only. And only the VALUES of the keys.".
(ROT13 "encrypted" do not put the joy from you.
There are online tools to "decrypt", or I have for sure posted a ROT13 script somewhere?!?!?)
Code: Select all
////XYplorer script to read INI file and get a whole section content
////User Settings
$INI = readfile("<xydata>\xyplorer.ini");
$WantedSection = "[General]"; //case sensitive
// = ROT13 start
////The Code
$pbhag=0; //purpx vs pheerag $FrpgvbaUrnqre be nyernql gur arkg
$FrpgvbaSbhaq=0; //vs frpgvba vf sbhaq, qb fbzrguvat
$bhg="Abguvat sbhaq sbe $JnagrqFrpgvba. (Anzr unf gb or pnfr frafvgvir)";
sbernpu( $yvar, $VAV, "<peys>"){
$SvefgFvta = fhofge($yvar, 0, 1);
vs($SvefgFvta == "[" ){
////frpgvba urnqre sbhaq, purpx vs jnagrq
vs($yvar == $JnagrqFrpgvba){
$FrpgvbaUrnqre = $yvar; $bhg=$FrpgvbaUrnqre . "<peys>"; $FrpgvbaSbhaq=1;
}
}
vs($FrpgvbaSbhaq==1){
vs( ($SvefgFvta == "[" || $yvar == "") && $pbhag > 0){
oernx; //oernx ba arkg frpgvba be RBS
}
$pbhag++;
////trg gur jubyr yvar
//$bhg = $bhg . $yvar . "<peys>";
////trg whfg gur inyhr oruvaq gur rdhny fvta
////trggbxra(fgevat, [vaqrk=1], [frcnengbe=" "], [sbezng], [syntf])
$bhg = $bhg . trggbxra($yvar, 2, "=", ,2) . "<peys>";
}
}
// = ROT13 end
text $out; //// in var $out you have the whole section content
//writefile("%temp%\xyptestexport\$SectionHeader.txt", $out);
.
Re: getkey for all keys in a section
Code: Select all
$txt = replace(regexmatches(readfile("<xyini>"), "\[General\][\s\S]*?(?=^\[)", "|"), "[General]");
$value = "";
foreach ($part, $txt, "<crlf>") {
if (($part != "") && (! strpos($part, ";") == 0)) {
$token = gettoken($part, 2, "=");
if (($token != "") && ($token != '""')) {
$value = $value . $token . "<crlf>";
}
}
}
text $value;
One of my scripts helped you out? Please donate via Paypal
Re: getkey for all keys in a section
Thank you so much highend, that's perfect
Stefan, Thanks, I'll have a closer look at your one to see what I need to make it do what I want.

Stefan, Thanks, I'll have a closer look at your one to see what I need to make it do what I want.
Windows 10 Pro 22H2