getkey for all keys in a section

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
kiwichick
Posts: 632
Joined: 08 Aug 2012 04:14
Location: Pahiatua, New Zealand

getkey for all keys in a section

Post by kiwichick »

Hi there,

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

highend
Posts: 14147
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: getkey for all keys in a section

Post by highend »

readfile()
regexmatch() / regexreplace()
foreach loop to do whatever you want with each entry
One of my scripts helped you out? Please donate via Paypal

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: getkey for all keys in a section

Post by Stefan »

kiwichick wrote:How would I use getkey (or would I use something else instead) to get ALL of the keys in a section?
Depends on the format of your ini, I guess.

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
...
...
you could just iterate over that section, like

Code: Select all

    while($loop <= $SectionCount){
        $array  = $array . getkey($loop . "_Date", "Toolbars",  $INIname) . "|";
        $loop++;
    }
http://www.xyplorer.com/xyfc/viewtopic. ... 295#p60295

admin
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

Post by admin »

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>");

highend
Posts: 14147
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: getkey for all keys in a section

Post by highend »

Actually it is possible by leaving the key empty:
Hard to know if it's not mentioned in the help file *g*
One of my scripts helped you out? Please donate via Paypal

admin
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

Post by admin »

It's a known Windows standard (when you know the API). :)

kiwichick
Posts: 632
Joined: 08 Aug 2012 04:14
Location: Pahiatua, New Zealand

Re: getkey for all keys in a section

Post by kiwichick »

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>");
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.

Cheers.

Stefan - Thanks, I'll go check your suggestions out now.
Windows 10 Pro 22H2

admin
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

Post by admin »

Well, once you have the keys it's easy, no?

kiwichick
Posts: 632
Joined: 08 Aug 2012 04:14
Location: Pahiatua, New Zealand

Re: getkey for all keys in a section

Post by kiwichick »

admin wrote:Well, once you have the keys it's easy, no?
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.
Windows 10 Pro 22H2

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: getkey for all keys in a section

Post by Stefan »

kiwichick wrote: Stefan - Thanks, I'll go check your suggestions out now.
How it goes? Did you worked it out?

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.

klownboy
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

Post by klownboy »

I hope that reg key you're displaying is bogus or I'd delete it... :D

kiwichick
Posts: 632
Joined: 08 Aug 2012 04:14
Location: Pahiatua, New Zealand

Re: getkey for all keys in a section

Post by kiwichick »

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.
Windows 10 Pro 22H2

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: getkey for all keys in a section

Post by Stefan »

buddies... of course that was neither my name nor a valid key :naughty: :biggrin: :appl:


kiwichick wrote:What I want is to get keys from ONE section only. And it to be only the VALUES of the keys.
Just in case you got stuck, here is a example code
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);
  


.

highend
Posts: 14147
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: getkey for all keys in a section

Post by highend »

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;
Strips out empty lines, lines beginning with a semicolon, empty values and values containing only ""...
One of my scripts helped you out? Please donate via Paypal

kiwichick
Posts: 632
Joined: 08 Aug 2012 04:14
Location: Pahiatua, New Zealand

Re: getkey for all keys in a section

Post by kiwichick »

Thank you so much highend, that's perfect :appl:

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

Post Reply