Page 1 of 1

How to get ("selecteditemsnames") for "basenames" only

Posted: 12 Sep 2012 02:14
by kiwichick
Hi there,

I see the get(selecteditems...) command is only for paths and fullnames. What would be the equivalent to return selected items basenames?

Or how would I use get("curitem", "base") in a foreach loop?

Or maybe I'm going about everything the wrong way. I want to create new txt files named after selected item's basenames (obviously to avoid the selected item's extension being included in the txt filename).

I've tried this but it includes the extension in the new name:

Code: Select all

$lst = get(selecteditemsnames);

 foreach($tk, $lst, "<crlf>",) {
  copytext "$tk";
  new("<clipboard>.txt");

  }
And this doesn't include the extension but it only works on the last selected item:

Code: Select all

$lst = get("curitem", "base");

 foreach($tk, $lst, "<crlf>",) {
  copytext "$tk";
  new("<clipboard>.txt");

  }

Re: How to get ("selecteditemsnames") for "basenames" only

Posted: 12 Sep 2012 06:51
by Stefan
If you use

::msg get("SelectedItemsPathNames");
or
::msg get("SelectedItemsNames");

you have to write code to extract the wanted parts from that full strings.





To just get the base of the selected items use

::msg report("{basename}"|,1);

Here each item is separated by an '|' to fit the standard of the foreach loop.



You could also use for example something like:

Code: Select all

 $a="";
 while(true){
  if ("<curbase>"==""){break;}
  $a = $a . "<curbase>|";
  //msg "<curbase>",1;
  sel "+1";
 }
 text $a;
 //foreach($item, $a){ ...}



Find more info about that into the help and inspect a few
other scripts from the script forum to see examples how it works.

Re: How to get ("selecteditemsnames") for "basenames" only

Posted: 12 Sep 2012 08:33
by highend
Just use getpathcomponent() to extract specific parts from a file / foldername in you foreach loop.

Re: How to get ("selecteditemsnames") for "basenames" only

Posted: 12 Sep 2012 08:47
by FluxTorpedoe
Hi'
I just saw that highend beat me to it ;)
There's probably other ways but this (verbose) one should suit you:

Code: Select all

  foreach($myitem, get("SelectedItemsPathNames", "|"), "|") {
    $mytextfile=getpathcomponent($myitem, "base");
    new("$mytextfile.txt");    
  }

Re: How to get ("selecteditemsnames") for "basenames" only

Posted: 12 Sep 2012 09:11
by highend
You can make it one line shorter:

Code: Select all

foreach($myitem, get("SelectedItemsPathNames", "|"), "|") {
    new(getpathcomponent($myitem, "base") . ".txt");    
  }

Re: How to get ("selecteditemsnames") for "basenames" only

Posted: 13 Sep 2012 01:50
by kiwichick
Thanks everyone!!! Perfecto :appl: