How to use Rename Special to rename multiple parts of file?

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
zBernie
Posts: 181
Joined: 08 Dec 2016 17:20

How to use Rename Special to rename multiple parts of file?

Post by zBernie »

I've looked at the manual for ways to rename the file below using RegExp Rename and Search and Replace, but am still coming up short. I can rename parts of it but not all of it. How can I rename the example video file as shown below?

Some.File.1999.1080p.BluRay.x265-ABCCC.mp4

Renamed to:

Some File (1999).mp4

RalphM
Posts: 2145
Joined: 27 Jan 2005 23:38
Location: Cairns, Australia

Re: How to use Rename Special to rename multiple parts of file?

Post by RalphM »

This can certainly be done by using regex rename but I assume the example you provided is just that - an example.
The stability of any regex depends on the reliable structure of the filenames you feed it.

First I would replace all the "." for spaces, bar the one before the extension, use File/Rename Special/Search and Replace and use the following code (note the space after /):

Code: Select all

./ 
Then, if the first four digits are always the year you want to retain, along with all the letters before it, then use File/Rename Special/RegExp Rename and use something like this:

Code: Select all

^(.*\W)(\d{4})\W.*(\..{3,})$ > $1($2)$3
This worked with your given example but you need to test this approach with more data.
Once you're happy with the results you might want to combine the two rename steps into a script that does it all.
Ralph :)
(OS: W11 26H2 Home x64 - XY: Current x64 beta - Office 2024 64-bit - Display: 1920x1080 @ 125%)

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

Re: How to use Rename Special to rename multiple parts of file?

Post by highend »

Or (if that example is really the pattern^^): ^(.+?)\.(.+?)\.(\d+)(.*?)(\.[^.]+)$ > $1 $2 ($3)$5
One of my scripts helped you out? Please donate via Paypal

WirlyWirly
Posts: 332
Joined: 21 Oct 2020 23:33
Location: XY 64-Bit | Win 11 @ 100% (3440x1440)

Re: How to use Rename Special to rename multiple parts of file?

Post by WirlyWirly »

Not exactly an XY solution, but if you're trying to rename movie/series to Kodi/Plex format, I recommend FileBot.

I have an instance of it running in a docker container so it can monitor a particular directory. It acts on any new files that get added, parses the filename, and then compares it against your preferred metadata site for the correct title. It will even organize it into your library based on filetype/genre/actors/studio/etc. Works great, very accurate.

There are some free alternatives I can't recall, but like XY, I find filebot to be easily worth the asking price.

zBernie
Posts: 181
Joined: 08 Dec 2016 17:20

Re: How to use Rename Special to rename multiple parts of file?

Post by zBernie »

highend wrote: ↑03 Apr 2022 11:39 Or (if that example is really the pattern^^): ^(.+?)\.(.+?)\.(\d+)(.*?)(\.[^.]+)$ > $1 $2 ($3)$5
Perfect, thank you.

zBernie
Posts: 181
Joined: 08 Dec 2016 17:20

Re: How to use Rename Special to rename multiple parts of file?

Post by zBernie »

WirlyWirly wrote: ↑03 Apr 2022 16:19 Not exactly an XY solution, but if you're trying to rename movie/series to Kodi/Plex format, I recommend FileBot.

I have an instance of it running in a docker container so it can monitor a particular directory. It acts on any new files that get added, parses the filename, and then compares it against your preferred metadata site for the correct title. It will even organize it into your library based on filetype/genre/actors/studio/etc. Works great, very accurate.

There are some free alternatives I can't recall, but like XY, I find filebot to be easily worth the asking price.
Thanks, I found they have a version for Windows. I'll check and see if there is a version for Synology.

zBernie
Posts: 181
Joined: 08 Dec 2016 17:20

Re: How to use Rename Special to rename multiple parts of file?

Post by zBernie »

RalphM wrote: ↑03 Apr 2022 11:16 This can certainly be done by using regex rename but I assume the example you provided is just that - an example.
The stability of any regex depends on the reliable structure of the filenames you feed it.

First I would replace all the "." for spaces, bar the one before the extension, use File/Rename Special/Search and Replace and use the following code (note the space after /):

Code: Select all

./ 
Then, if the first four digits are always the year you want to retain, along with all the letters before it, then use File/Rename Special/RegExp Rename and use something like this:

Code: Select all

^(.*\W)(\d{4})\W.*(\..{3,})$ > $1($2)$3
This worked with your given example but you need to test this approach with more data.
Once you're happy with the results you might want to combine the two rename steps into a script that does it all.
Thank you!

zBernie
Posts: 181
Joined: 08 Dec 2016 17:20

Re: How to use Rename Special to rename multiple parts of file?

Post by zBernie »

RalphM wrote: ↑03 Apr 2022 11:16 This can certainly be done by using regex rename but I assume the example you provided is just that - an example.
The stability of any regex depends on the reliable structure of the filenames you feed it.

First I would replace all the "." for spaces, bar the one before the extension, use File/Rename Special/Search and Replace and use the following code (note the space after /):

Code: Select all

./ 
Then, if the first four digits are always the year you want to retain, along with all the letters before it, then use File/Rename Special/RegExp Rename and use something like this:

Code: Select all

^(.*\W)(\d{4})\W.*(\..{3,})$ > $1($2)$3
This worked with your given example but you need to test this approach with more data.
Once you're happy with the results you might want to combine the two rename steps into a script that does it all.
I'm trying to script the replace and RegExp commands you provided. I've tried numerous permutations of the commands below using the Scripting -> Run Script menu item. But regardless of what I do the file remains unchanged. Can you tell me what I'm doing wrong?

Code: Select all

$var_file = "<curname>";

$var_file = replace($var_file, ".", " ");

//replace($var_file, ".", [replacement=" "], [matchcase=0], [start=1], [count=3]);

//$var_file = RegExReplace($x, "^(.*\W)(\d{4})\W.*(\..{3,})$", "$1($2)$3");

RalphM
Posts: 2145
Joined: 27 Jan 2005 23:38
Location: Cairns, Australia

Re: How to use Rename Special to rename multiple parts of file?

Post by RalphM »

Usual culprit for scripts not working: First line needs to start with at least one space.
Then use step mode to see what each command in your script actually does.
Ralph :)
(OS: W11 26H2 Home x64 - XY: Current x64 beta - Office 2024 64-bit - Display: 1920x1080 @ 125%)

zBernie
Posts: 181
Joined: 08 Dec 2016 17:20

Re: How to use Rename Special to rename multiple parts of file?

Post by zBernie »

RalphM wrote: ↑04 Apr 2022 02:19 Usual culprit for scripts not working: First line needs to start with at least one space.
Then use step mode to see what each command in your script actually does.
That's odd -- I have scripts contained in custom buttons that work without starting with a space.

zBernie
Posts: 181
Joined: 08 Dec 2016 17:20

Re: How to use Rename Special to rename multiple parts of file?

Post by zBernie »

RalphM wrote: ↑03 Apr 2022 11:16 This can certainly be done by using regex rename but I assume the example you provided is just that - an example.
The stability of any regex depends on the reliable structure of the filenames you feed it.

First I would replace all the "." for spaces, bar the one before the extension, use File/Rename Special/Search and Replace and use the following code (note the space after /):

Code: Select all

./ 
Then, if the first four digits are always the year you want to retain, along with all the letters before it, then use File/Rename Special/RegExp Rename and use something like this:

Code: Select all

^(.*\W)(\d{4})\W.*(\..{3,})$ > $1($2)$3
This worked with your given example but you need to test this approach with more data.
Once you're happy with the results you might want to combine the two rename steps into a script that does it all.
Here is a scripted solution. So far it works with all of the movie files I've tried it on.

Code: Select all

$var_file = <curname>;
   $cur_file = <curbase>;

   $new_file = replace($var_file, ".", " ");
   renameitem("$new_file", "$var_file");

   $renamed_file = <curname>;
   $new_file = RegExReplace($renamed_file, "^(.*\W)(\d{4})\W.*(\..{3,})$", "$1($2)$3");

   renameitem("$new_file", <curname>);

RalphM
Posts: 2145
Joined: 27 Jan 2005 23:38
Location: Cairns, Australia

Re: How to use Rename Special to rename multiple parts of file?

Post by RalphM »

zBernie wrote: ↑04 Apr 2022 05:13That's odd -- I have scripts contained in custom buttons that work without starting with a space.
You are right, I had it the wrong way around, ALL but the first line of a multi-line script have to be indented.
However, with highend's RegEx from above you could have turned this into a simple one-liner:

Code: Select all

renameitem(RegExReplace(<curname>, "^(.+?)\.(.+?)\.(\d+)(.*?)(\.[^.]+)$", "$1 $2 ($3)$5"));
The next step will be to turn this into a script that operates on all selected files not just the current one.
You should read up on "selitems" and "foreach" loops in the help for ideas on how to make this happen.
Ralph :)
(OS: W11 26H2 Home x64 - XY: Current x64 beta - Office 2024 64-bit - Display: 1920x1080 @ 125%)

Post Reply