Replace existing numbers with matching to new ones?

A swapping-ground for Regular Expression syntax

Replace existing numbers with matching to new ones?

Postby Breaky » Fri Apr 23, 2021 2:10 pm

Hi,

I had: Multiple files named "S01E001 - title of episode" to "S01E483 - title of episode". All those episodes are part of 9 seasons.
So I placed all relevant episodes in corresponding season folders and changed out "S01" to "S0x", where "x" is the correct season number.

However, season 9 for example, the episode numbering should go from S09E001 to S09E039.

S09E383 corresponds with S09E001
S09E421 corresponds with S09E039

So I want to somehow match and replace this AND skip the missing numbers. So for example episode 385 is missing (so no 003), but with 386 it keeps counting and thus chaning that one to 004.

I hope I'm explaining this right. Would love some help with this, any help is really appreciated!

Regards,

Breaky
Breaky
 
Posts: 2
Joined: Fri Apr 23, 2021 1:23 pm

Re: Replace existing numbers with matching to new ones?

Postby Luuk » Fri Apr 23, 2021 6:10 pm

The RegEx(1) will not conduct math, so it could never conduct the match/replace-with-numbering.
Im thinking only javascript will conduct match/replace-with-numbers (when numbers require the math).
I can describe the math, if there is experts to convert this math into the javascript?...

First, look at the first name (lowest E###).. Subtract 1 from ### to set your variable.
So if the very first filename was S09E383... Set a variable to 382... Then just subtract 382 from the E### numbers...
E383 ==> E001 (383-382)
E384 ==> E002 (384-382)
E385 ==> E003 (385-382)
E390 ==> E008 (390-382)
E391 ==> E009 (391-382)

Its unfortunate, but I dont know how to conduct the javascript, except like inside of the Filters(12) condition.
If its a big problem, I could write a batch for this, but hoping there is experts to explain this in the javascript.
Maybe another way, if not too many missing episodes, is to create the counterfeit episodes, and then using Numbering(10).
Luuk
 
Posts: 201
Joined: Fri Feb 21, 2020 10:58 pm

Re: Replace existing numbers with matching to new ones?

Postby Breaky » Mon Apr 26, 2021 11:01 pm

Hi Luuk, thanks for your reply.

Your solution sounds so simple. Just subtract the number of the first episode (-1) from each episode number in the filename. I've tried googling for a solution (in Windows) but am unable to find a solution (I understand and can work with haha).

I found this:https://stackoverflow.com/questions/55888298/rename-the-end-of-filename-by-subtracting-value but I'm not sure how to use this and what the posts are referring to.
Breaky
 
Posts: 2
Joined: Fri Apr 23, 2021 1:23 pm

Re: Replace existing numbers with matching to new ones?

Postby Admin » Tue Apr 27, 2021 3:18 am

Hi, what would be the math to be applied to each name? Then once the math is known, it can be done with Javascript in Bulk Rename Utility?
Admin
Site Admin
 
Posts: 2031
Joined: Tue Mar 08, 2005 8:39 pm

Re: Replace existing numbers with matching to new ones?

Postby Luuk » Wed Apr 28, 2021 4:24 am

Javascript does easily conduct the math, because look at this... viewtopic.php?f=2&t=4849&p=13030 except that its conducting math to the end of filenames, but the number for conducting math does not come from the lowest filename in each folder.

So it still needs a way to conduct math in the middle, but also setting a variable for each new folder, OR just set a variable manually to conduct one folder at a time. Its easy conducting this variable with a batch, but Im no idea how the javascript would conduct different "math per folder", unless maybe someone renamed each parent folder to have the number needed for the math.

If its me, Im thinking the easiest way is to invent a batch using something command-line like the exiftool, but I would need to know many things like the file extensions, if there is other files to never conduct, etc. But after knowing the environment, Im thinking it would be very easy to invent a batch for this.
Luuk
 
Posts: 201
Joined: Fri Feb 21, 2020 10:58 pm


Return to Regular Expressions


cron