Page 1 of 1

Is there a script that can remove after phrase

Posted: 17 Aug 2021 19:47
by Lighthammer
Greetings,

I did a search to see if I could find a topic on this, but after page 3, I didn't see anything, so pardon me if this was covered in the past.

I'm trying to create a script that will remove after a specific phrase.

For my example, I am doing this currently:

Code: Select all

rename s, "2021/[2021] [] [1080p] [H265]"; 
I would like to then remove EVERYTHING after [H265] and ensure I set the proper extension is set.}

I figure this can probably be done with a regular expression, but I am unsure of how to parse the commands.

Thanks in advance

Re: Is there a script that can remove after phrase

Posted: 17 Aug 2021 20:04
by highend

Code: Select all

    $newName = regexreplace(<curitem>, "^(.+\\)(.*\[h265\])(.*?)(\.[^.]+$)", "$2$4");
    renameitem($newName, <curitem>);

Re: Is there a script that can remove after phrase

Posted: 17 Aug 2021 20:12
by Lighthammer
That script does the job, but seemingly only on one item at a time if I select, say 10 things to rename.

Is that a limitation of the script or XY?

Re: Is there a script that can remove after phrase

Posted: 17 Aug 2021 20:16
by Lighthammer
Thanks for the help so far.

I also wanted to know if you can name the script for custom buttons so you don't have a text box the size of your screen when you click it.

I'd GUESS that's part of the script.

Re: Is there a script that can remove after phrase

Posted: 17 Aug 2021 20:23
by Horst
Of course a script can be arbitrary named.
Also you didn't ask for more than one entry and so the script doesn't contain a loop for any selections.
I think you should now spend some time to read the help about scripting in XY
and look around in the many examples in this forum.

Re: Is there a script that can remove after phrase

Posted: 17 Aug 2021 20:33
by Knighthammer
Horst wrote: ↑17 Aug 2021 20:23 Of course a script can be arbitrary named.
Also you didn't ask for more than one entry and so the script doesn't contain a loop for any selections.
I think you should now spend some time to read the help about scripting in XY
and look around in the many examples in this forum.
You're asking someone to learn without examples. The reason I asked for is I already took a look around and didn't find what I was looking for, so I asked.

A bit elitest just telling someone "Go learn via osmosis", don't you think?

I'm thankful for help, but there's no need to derail a thread when someone is trying to figure out how to do something.

Also, for the record, I did go take a look around and I didn't find the question in of itself. I also didn't find anyone else deciding to chime in and say "Tuff, that's not what you asked for, now go figure it out for yourself".

Not cool man =(.

Re: Is there a script that can remove after phrase

Posted: 17 Aug 2021 20:42
by highend

Code: Select all

    foreach($item, <get selecteditemspathnames>, <crlf>, "e") {
        $newName = regexreplace($item, "^(.+\\)(.*\[h265\])(.*?)(\.[^.]+$)", "$2$4");
        renameitem($newName, $item);
    }

Re: Is there a script that can remove after phrase

Posted: 17 Aug 2021 20:56
by Knighthammer
Thanks Highend, I'll try this.

Re: Is there a script that can remove after phrase

Posted: 17 Aug 2021 21:09
by Knighthammer
@Highend

So, perhaps one more question.

Now I'm taking the script you made and trying to add in additional commands and it seems to keep looping on the first one then break on the second, so, I know I broke something.

Here's my example:

Code: Select all

foreach($item, <get selecteditemspathnames>, <crlf>, "e") 
    {
        rename s, "2021/[2021] [] [1080p] [H265]";
    }
    {
        $newName = regexreplace($item, "^(.+\\)(.*\[h265\])(.*?)(\.[^.]+$)", "$2$4");
        renameitem($newName, $item);
    }
I'm not sure that the normal scripting in XY is compatible with regular expressions so I suspect this is in part how I'm breaking it.

Re: Is there a script that can remove after phrase

Posted: 17 Aug 2021 21:20
by highend
You'd better read the help file^^

Code: Select all

    foreach($item, <get selecteditemspathnames>, <crlf>, "e") {
        $newName = replace(gpc($item, "base"), "2021", "[2021] [] [1080p] [H265]");
        $newName = regexreplace($newName, "^(.*\[h265\])(.*?)$", "$1");
        renameitem($newName, $item);
    }

Re: Is there a script that can remove after phrase

Posted: 17 Aug 2021 21:58
by Knighthammer
highend wrote: ↑17 Aug 2021 21:20 You'd better read the help file^^

Code: Select all

    foreach($item, <get selecteditemspathnames>, <crlf>, "e") {
        $newName = replace(gpc($item, "base"), "2021", "[2021] [] [1080p] [H265]");
        $newName = regexreplace($newName, "^(.*\[h265\])(.*?)$", "$1");
        renameitem($newName, $item);
    }
Ok, I see, brackets stick around what you're doing there.

I did check out the helpfiles, but they are SURPRISINGLY limited, at least where Regexpressions go. For doing general scripting supported by XY natively, they're pretty good.

Someone linked this guy:
https://www.scriptbuddy.com/login.php

Looks interesting enough to go check out.

I've really only worked with LUA in the past (outside of DOS stuff).

Thanks again.