How do you loop through items and set each as current item?

Discuss and share scripts and script files...
Post Reply
mydarkpassenger
Posts: 31
Joined: 19 Apr 2014 19:39

How do you loop through items and set each as current item?

Post by mydarkpassenger »

Hello, I have a questions in regards to how scripting works in xyplorer. I have a programming background but there's a couple things I'm unsure of in xys. First, it seems like a lot of functions are based on the assumption that there's only one item. I'm curious how you would loop through the selected items and set an item as the current item? For example, if I do this:

foreach($i, get(SelectedItemsNames, "|")) {
echo <curbase>;
}

I would get the last item every time. However, how would I get the curbase for the other items.

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

Re: How do you loop through items and set each as current it

Post by highend »

Code: Select all

    foreach($i, get(SelectedItemsNames, "|")) {
        echo getpathcomponent($i, "base");
    }
Ofc you have to use $i instead of <curbase> again...
One of my scripts helped you out? Please donate via Paypal

klownboy
Posts: 4459
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.8037 at 100% 2560x1440

Re: How do you loop through items and set each as current it

Post by klownboy »

I'm not sure highend or mydarkpassenger if we're talking about the technique for building the list like...

Code: Select all

 $CBlist = "";
  foreach($i, get(SelectedItemsNames, "|")) {
        getpathcomponent($i, "base");
  $CBlist = $CBlist .  $i . "<crlf>" ;  
    }
 echo $CBlist;
Select some files and try it in Scripting | Run script...

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

Re: How do you loop through items and set each as current it

Post by highend »

set an item as the current item
He doesn't explicitly state that he wants to build a list :)
One of my scripts helped you out? Please donate via Paypal

klownboy
Posts: 4459
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.8037 at 100% 2560x1440

Re: How do you loop through items and set each as current it

Post by klownboy »

mydarkpassenger wrote:...how would I get the curbase for the other items.
I focused on that statement so I figured he was possibly interested in building the list, but only he knows. :)

mydarkpassenger
Posts: 31
Joined: 19 Apr 2014 19:39

Re: How do you loop through items and set each as current it

Post by mydarkpassenger »

I'm trying to work on methods to rename files. There's a couple of things I'd like to do:

1) I want the ability to get the parent folder's name and rename the file based on it. From what I gathered there's no property for this so it's going to probably involve splitting the file and getting the second to last index.

2) I want to be able to clean file names up. A lot of files I own have junk text in the name I want to remove. I plan to use string replacements to take care of this so I plan to put the junk text in a list and loop and removing it from the original string.

3) I want to be able to format certain text a certain way. For example, I have TV seasons with labels like s1e12. I want to format it so it will be S01E12. I might have a title in the name as well and I don't want that all upper case, just the season, I would want the titles capitalized. I'm not completely sure the best way to do this though. My guess is I can use a reg pattern for the season/episode match returning a string that is properly formatted and another string will be made from the remainder joined together.

So here's what I'm trying to do. Any help would be appreciated!

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

Re: How do you loop through items and set each as current it

Post by highend »

1.

Code: Select all

text getpathcomponent("<curitem>", "component", -2);
or $i instead of "<curitem>" for your foreach loop...

2.
E.g. via gettoken() (separated by spaces) and look it up in your list (strpos())

3.
regexreplace() & recase() are your friends
One of my scripts helped you out? Please donate via Paypal

mydarkpassenger
Posts: 31
Joined: 19 Apr 2014 19:39

Re: How do you loop through items and set each as current it

Post by mydarkpassenger »

Thank you highend. I'm going to check this out when I get home.

Post Reply