Renaming .yyyy

Advanced Renamer forum
#1 : 03/05-25 13:57
Alexander
Posts: 4
Hi! How to rename files containing ".yyyy" to "(yyyy)" (without quotes)? Where yyyy is the year, for example 1979.
#2 : 03/05-25 16:46
Delta Foxtrot
Posts: 468
Reply to #1:

Hi Alexander,

The short answer, and the one that you'll probably be able to use, is simply to use a Replace method with a regular expression to capture the four-digit number following a period:

(Leave out the quotation marks)
Replace: "\.(\d{4})"
Replace with: "($1)"
Occurrence: (This will depend on your filename structure, but probably All or 1st)
Use regular expressions: CHECKED
Apply to: Name

In the unlikely case of having more than one occurrence of a four-digit number following a period, you might be able to define the year more specifically. For instance, if all dates fall in the 20th or 21st centuries you could do something like this:

Replace: "\.([12][9012]\d\d)"
Replace with: "($1)"
(everything else the same)

This will only change a four-digit number if the first number is a 1 or a 2 and the second number is a 9, 0, 1, or 2. These are the only numbers that would be in the first and second postion of a date from 1900 to 2099. Of course, if you have other (period then) four-digit numbers that start like that but aren't year numbers, all bets are off. :)

Best,
DF
#3 : 03/05-25 17:00
Alexander
Posts: 4
Reply to #2:
Thanks a lot
#4 : 03/05-25 17:04
Delta Foxtrot
Posts: 468
Reply to #3:

I just realized, you can be more specific about the second example and avoid some problems with numbers like ".10nn", ".11nn", etc. For the "Replace:" field you could use:

\.((19|20)\d\d)

Again, probably not needed, but it's there if you want it.

Best,
DF