Page 1 of 1

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

Posted: 25 Apr 2014 14:14
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.

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

Posted: 25 Apr 2014 15:24
by highend

Code: Select all

    foreach($i, get(SelectedItemsNames, "|")) {
        echo getpathcomponent($i, "base");
    }
Ofc you have to use $i instead of <curbase> again...

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

Posted: 25 Apr 2014 15:49
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...

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

Posted: 25 Apr 2014 15:54
by highend
set an item as the current item
He doesn't explicitly state that he wants to build a list :)

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

Posted: 25 Apr 2014 16:05
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. :)

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

Posted: 25 Apr 2014 18:44
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!

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

Posted: 25 Apr 2014 19:04
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

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

Posted: 25 Apr 2014 19:23
by mydarkpassenger
Thank you highend. I'm going to check this out when I get home.