Page 1 of 1
Help with Loop.
Posted: 11 Oct 2010 23:31
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.
Re: Help with Loop.
Posted: 14 Oct 2010 22:56
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
Re: Help with Loop.
Posted: 15 Oct 2010 00:32
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!!!)
Re: Help with Loop.
Posted: 15 Oct 2010 08:52
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
Re: Help with Loop.
Posted: 19 Oct 2010 09:25
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!