Is there a script that can remove after phrase

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
Lighthammer
Posts: 12
Joined: 05 Oct 2019 01:24

Is there a script that can remove after phrase

Post 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

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

Re: Is there a script that can remove after phrase

Post by highend »

Code: Select all

    $newName = regexreplace(<curitem>, "^(.+\\)(.*\[h265\])(.*?)(\.[^.]+$)", "$2$4");
    renameitem($newName, <curitem>);
One of my scripts helped you out? Please donate via Paypal

Lighthammer
Posts: 12
Joined: 05 Oct 2019 01:24

Re: Is there a script that can remove after phrase

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

Lighthammer
Posts: 12
Joined: 05 Oct 2019 01:24

Re: Is there a script that can remove after phrase

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

Horst
Posts: 1419
Joined: 24 Jan 2021 12:27
Location: Germany

Re: Is there a script that can remove after phrase

Post 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.
Windows 11 Home, Version 26H2 (OS Build 26300.10075)
Portable x64 XYplorer (Actual version, including betas)
Display settings 1920 x 1080 Scale 100%
Everything 1.5.0.1424b (x64), Everything Toolbar 3.5, Listary Pro 7.1.0.47 beta

Knighthammer
Posts: 26
Joined: 05 May 2021 19:05

Re: Is there a script that can remove after phrase

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

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

Re: Is there a script that can remove after phrase

Post by highend »

Code: Select all

    foreach($item, <get selecteditemspathnames>, <crlf>, "e") {
        $newName = regexreplace($item, "^(.+\\)(.*\[h265\])(.*?)(\.[^.]+$)", "$2$4");
        renameitem($newName, $item);
    }
One of my scripts helped you out? Please donate via Paypal

Knighthammer
Posts: 26
Joined: 05 May 2021 19:05

Re: Is there a script that can remove after phrase

Post by Knighthammer »

Thanks Highend, I'll try this.

Knighthammer
Posts: 26
Joined: 05 May 2021 19:05

Re: Is there a script that can remove after phrase

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

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

Re: Is there a script that can remove after phrase

Post 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);
    }
One of my scripts helped you out? Please donate via Paypal

Knighthammer
Posts: 26
Joined: 05 May 2021 19:05

Re: Is there a script that can remove after phrase

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

Post Reply