Page 1 of 1

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

Posted: 03 Apr 2022 02:57
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

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

Posted: 03 Apr 2022 11:16
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.

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

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

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

Posted: 03 Apr 2022 16:19
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.

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

Posted: 03 Apr 2022 20:38
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.

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

Posted: 03 Apr 2022 20:39
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.

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

Posted: 03 Apr 2022 20:46
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!

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

Posted: 04 Apr 2022 00:58
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");

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

Posted: 04 Apr 2022 02:19
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.

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

Posted: 04 Apr 2022 05:13
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.

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

Posted: 09 Apr 2022 00:54
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>);

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

Posted: 09 Apr 2022 03:26
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.