Help with Loop.

Discuss and share scripts and script files...
Post Reply
SkyFrontier
Posts: 2341
Joined: 04 Jan 2010 14:27
Location: Pasárgada (eu vou!)

Help with Loop.

Post by SkyFrontier »

Guys,
I need to get some files as base to select their folder pairs.
Base files start with underscore and has .zip as extension. I'm looking for a way to get rid of both "_/.zip" so the resulting list can be used to select the folders, too. How?

This one almost does the first part of the job (it stops deleting the first underscore and reports all the rest with them):

Code: Select all

   selfilter "|_*.zip";
   Setting "AllowRecursion", 1;
   $files = Report("{Name}<crlf>", 1);
   substr $files, $files, 1;
   copytext $files;
And this one is failing to get list's next item, so it ends erasing all:

Code: Select all

   selfilter "|_*.zip";
   Setting "AllowRecursion", 1;
   $files = Report("{Name}<crlf>", 1);
    $Loop = 1;
    while(1)
    {
      IF ($ITEM==""){break;}
      substr $files, $files, 1;
    incr $Loop;
    }
   copytext $files;
Sample input:
_Mosaico.zip
_Vectorian_Giotto.zip
Sample result must be:
Mosaico
Vectorian_Giotto
Ideally the script should get both input/output selected for the next (last) step: throwing everything into a predefined folder.
Thank you.
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...

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

Re: Help with Loop.

Post by Stefan »

AFAIU you want smtg like:

Code: Select all

selfilter "_*.zip"; //_Mosaico.zip, _Vectorian_Giotto.zip

   $files =  Report("{BaseName}<crlf>", 1); //_Mosaico?_Vectorian_Giotto?


    $Loop = 1; //initialize Loop var
    $Array=""; //initialize Array var

    while(1) //Loop infinity
    {
      $ITEM = gettoken($files, $Loop, "<crlf>"); //get next token from $files
      IF ($ITEM==""){break;} //if token is empty => break Loop

	  //cut first char "_" and fill $Array with next token
      $Array = $Array . substr($ITEM, 1) . "|"; // Mosaico, Vectorian_Giotto
            //or step-by-step:
            //$TEMP = substr($ITEM, 1);
            //$TEMP = $TEMP . "|";
            //$Array = $Array . $TEMP;
            //$TEMP="";

    incr $Loop;
    }

   text $Array; //debug info
   selfilter $Array, d; //select items, d=dirs only
or for your case this shorter version may be enough:

Code: Select all

selfilter "_*.zip";                          //_Mosaico.zip, _Vectorian_Giotto.zip
   $files = "|" . Report("{BaseName}|", 1);  //|_Mosaico|_Vectorian_Giotto|
   $files = replace($files, "|_", "|");      //|Mosaico|Vectorian_Giotto|
   selfilter $files, d;     //select items, d=dirs only

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

Re: Help with Loop.

Post by SkyFrontier »

...and when I need to get both "_*.zip" and respective folder pairs, I'd just need to do this:

Code: Select all

   selfilter "_*.zip";                          //_Mosaico.zip, _Vectorian_Giotto.zip
   $files = "|" . Report("{BaseName}|", 1);  //|_Mosaico|_Vectorian_Giotto|
   $files = replace($files, "|_", "|");      //|Mosaico|Vectorian_Giotto|
   selfilter $files, d;     //select items, d=dirs only
   selfilter "_*.zip;$files";
Thank you very much, Stefan! File management has never been easier... (Time Machine, Time Machine, Time Machine!!!)
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...

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

Re: Help with Loop.

Post by Stefan »

SkyFrontier wrote:...and when I need to get both "_*.zip" and respective folder pairs, I'd just need to do this:

Code: Select all

   selfilter "_*.zip";                          //_Mosaico.zip, _Vectorian_Giotto.zip
   $files = "|" . Report("{BaseName}|", 1);  //|_Mosaico|_Vectorian_Giotto|
   $files = replace($files, "|_", "|");      //|Mosaico|Vectorian_Giotto|
   selfilter $files, d;     //select items, d=dirs only
   selfilter "_*.zip;$files";
Thank you very much, Stefan! File management has never been easier... (Time Machine, Time Machine, Time Machine!!!)
>...and when I need to get both "_*.zip" and respective folder pairs

Code: Select all

   selfilter "_*.zip";                          //_Mosaico.zip, _Vectorian_Giotto.zip
   $files = "|" . Report("{BaseName}|", 1);  //|_Mosaico|_Vectorian_Giotto|
   $files = replace($files, "|_", "|");      //|Mosaico|Vectorian_Giotto|
   selfilter $files;     //select all matching items, without "d"-parameter no matter if dir or file

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

Re: Help with Loop.

Post by SkyFrontier »

This one and the file-based favorites thing are really making my day, Stefan!
Greatest feature on this one: it's getting partial matches even on the final portion of the file name, and it's easier to "Move Here to New Subfolder" (CTRL+SHIFT+X) THEN sort out stuff I don't want in the selection than what I was doing so far: selecting the grouped "_*.zip" files, moving them to a folder, put that folder on pane 1 and on pane 2, manual selecting matches to the eye, then moving everything to the pane 1 (not to mention the times when we had no "restore selection", available since v9.50.0112).
Again, thank you for the scripts - and Don for the features!
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...

Post Reply