Rename - Change Date format in File Name

I get a lot of files from colleagues at work where they put a date at the end of the filename such as...

XYZ presentation filename 09302011.pptx

Once you get a series of these files, they aren't ordered correctly so I often change them to a YYYY.MM.DD format...

XYZ presentation filename 2011.09.30.pptx

What is the regular expression to do this?

Old Name: (.*)([0-9][0-9])([0-9][0-9])([0-9][0-9][0-9][0-9])(\.[^.]+)
New Name: \1\4.\2.\3\5
Type: Regular Expressions

1 Like

Thanks. That works but it's not flexible for other situations (which I intentionally didn't includ in the initial post). How could I modify it if the date is only 7 char instead of 8 (9302011 instead of 09302011) or if it had separators (. or -)? With this as a template, I could modify it to handle these different scenarios and then put them in a single button...

Rename PRESET=DateChange1 Rename PRESET=DateChange2

But is there a more flexible way?

It's much easier to make a regexp if the full complexity of what you need to do is known up-front.

This one should get you most of the way there:

Old Name:
(.*[^0-9])([0-9]?[0-9])[-.]?([0-9][0-9])[-.]?([0-9][0-9][0-9][0-9])(\.[^.]+)

New Name:
\1\4.\2.\3\5


1 Like

Thanks. I've now got a series of 6 presets being called by a single button. It's working well so far and I can live with the occasional exception.

@Leo
I am trying to understand this (I just don't understand RegExp) and trying to do something similar, but:
from: Recipient Created Tax Invoice - 01-07-2020.pdf
to: Recipient Created Tax Invoice - 2020.07.01.pdf
Date format of the file is dd-mm-yyyy
I am trying to reformat so the files can be sorted by date. I have tried playing around with your answer, but it never ends well for me :open_mouth:

(why do most people insist on manually naming/creating automated file output putting the day first so date-based files are unsortable?

Because that's the commonly used format in every day usage in some places,

1 Like

The new forum software messed up the regex codes in the old post from the old forum software. I've edited the post so the codes should work now.

Tx Leo,
Works perfectly now :slight_smile:

It was a rhetorical Q. :wink: