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

Discuss and share scripts and script files...
Post Reply
kiwichick
Posts: 675
Joined: 08 Aug 2012 04:14
Location: Windows 10 Pro 22H2, 150% scaling

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

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

  }
Windows 10 Pro 22H2

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

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

Post 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.

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

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

Post by highend »

Just use getpathcomponent() to extract specific parts from a file / foldername in you foreach loop.
One of my scripts helped you out? Please donate via Paypal

FluxTorpedoe
Posts: 906
Joined: 05 Oct 2011 13:15

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

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

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

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

Post by highend »

You can make it one line shorter:

Code: Select all

foreach($myitem, get("SelectedItemsPathNames", "|"), "|") {
    new(getpathcomponent($myitem, "base") . ".txt");    
  }
One of my scripts helped you out? Please donate via Paypal

kiwichick
Posts: 675
Joined: 08 Aug 2012 04:14
Location: Windows 10 Pro 22H2, 150% scaling

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

Post by kiwichick »

Thanks everyone!!! Perfecto :appl:
Windows 10 Pro 22H2

Post Reply