Page 1 of 1

getkey for all keys in a section

Posted: 19 Sep 2013 05:58
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.

Re: getkey for all keys in a section

Posted: 19 Sep 2013 11:56
by highend
readfile()
regexmatch() / regexreplace()
foreach loop to do whatever you want with each entry

Re: getkey for all keys in a section

Posted: 19 Sep 2013 14:14
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

Re: getkey for all keys in a section

Posted: 19 Sep 2013 14:24
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>");

Re: getkey for all keys in a section

Posted: 19 Sep 2013 14:52
by highend
Actually it is possible by leaving the key empty:
Hard to know if it's not mentioned in the help file *g*

Re: getkey for all keys in a section

Posted: 19 Sep 2013 14:55
by admin
It's a known Windows standard (when you know the API). :)

Re: getkey for all keys in a section

Posted: 20 Sep 2013 04:15
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.

Re: getkey for all keys in a section

Posted: 20 Sep 2013 07:35
by admin
Well, once you have the keys it's easy, no?

Re: getkey for all keys in a section

Posted: 20 Sep 2013 10:09
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.

Re: getkey for all keys in a section

Posted: 22 Oct 2013 22:38
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...
.

Re: getkey for all keys in a section

Posted: 22 Oct 2013 23:07
by klownboy
I hope that reg key you're displaying is bogus or I'd delete it... :D

Re: getkey for all keys in a section

Posted: 23 Oct 2013 03:02
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.

Re: getkey for all keys in a section

Posted: 23 Oct 2013 09:34
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);
  


.

Re: getkey for all keys in a section

Posted: 23 Oct 2013 11:22
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 ""...

Re: getkey for all keys in a section

Posted: 24 Oct 2013 05:00
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.