Reformat the date in file names

A swapping-ground for Regular Expression syntax

Re: Reformat the date in file names

Postby Adrian.Bradescu » Fri Jan 15, 2021 1:56 pm

Hi,

Can you help me please with changing this date format 22 Aug 2018 into this 20180822?
Is it possible? :?:
Thanks!
Adrian.Bradescu
 
Posts: 3
Joined: Fri Jan 15, 2021 1:50 pm

Re: Reformat the date in file names

Postby Luuk » Fri Jan 15, 2021 5:04 pm

Greetings Adrian. This very common question, but now Im not finding anywhere. Its needing checkmark in "v2" , but with long commands, so best saving it.
Match...
Code: Select all
(\d\d) (Jan|Feb|Mar|Apr|Mai|Jun|Jul|Aug|Sep|Okt|Nov|Dez) ((19|20)\d\d)(?X)(:Jan)(?X)(:Feb)(?X)(:Mar)(?X)(:Apr)(?X)(:Mai)(?X)(:Jun)(?X)(:Jul)(?X)(:Aug)(?X)(:Sep)(?X)(:Okt)(?X)(:Nov)(?X)(:Dez)
Replace...
Code: Select all
$3:$2$1(?X)01(?X)02(?X)03(?X)04(?X)05(?X)06(?X)07(?X)08(?X)09(?X)10(?X)11(?X)12
Its first replacing Month with :Month, then :Month with ##, because elsewise its a LOT more typing.
Luuk
 
Posts: 208
Joined: Fri Feb 21, 2020 10:58 pm

Re: Reformat the date in file names

Postby Adrian.Bradescu » Mon Jan 18, 2021 5:30 pm

Thank you Luuk, it works smoothly and fine on the last version of Bulk Rename Utility on my personal desktop.

The issue I have, is that on another laptop I have an old version of Bulk Rename Utility (2.7.1.3) and a huge no. of documents to be renamed. Since is the company laptop they don"t alow us to install any outside software.
I am not a lazy guy (to copy all huge no of documents from laptop to my desktop, as a final solution) but... there is any chance to find a command to do the same, that works on this old Bulk version?
The version I have is an executable file and cannot be updated without IT department approval...
Many Thanks!
Adrian.Bradescu
 
Posts: 3
Joined: Fri Jan 15, 2021 1:50 pm

Re: Reformat the date in file names

Postby Luuk » Mon Jan 18, 2021 10:19 pm

Yes its possible because Im just posted to where someone does it in "Character Translations"! viewtopic.php?f=12&t=4780&start=0
At first, Im thinking to just use the very first regex from the "v2" like...
(\d\d) (Jan|Feb|Mar|Apr|Mai|Jun|Jul|Aug|Sep|Okt|Nov|Dez) ((19|20)\d\d)
\3:\2\1
With the pasting in "Character Translations" to be like..
:,J,a,n=0,1
:,F,e,b=0,2

But it only conducts properly when filenames are to be exact dates, because the other text is destroyed. So then modifying to include more text...
(.*\d\d) (Jan|Feb|Mar|Apr|Mai|Jun|Jul|Aug|Sep|Okt|Nov|Dez) ((19|20)\d\d.*)
\3:\2\1

But then the ordering for extra text is getting destroyed, so still studying the post to find a better solution. There is "portable version" .exe so that does not require installation, if its to be acceptable.
Luuk
 
Posts: 208
Joined: Fri Feb 21, 2020 10:58 pm

Re: Reformat the date in file names

Postby Luuk » Wed Jan 20, 2021 10:29 pm

Never mind, Im fixing this after discovering the problem is actually inside the regex! The .* must be alone in (.*) to get a different group number, so then easy to change the ordering. So this can also work, but only if "Character Translations" was still invented with the old version?

Match...
(.*)(\d\d) (Jan|Feb|Mar|Apr|Mai|Jun|Jul|Aug|Sep|Okt|Nov|Dez) ((19|20)\d\d)(.*)
Replace...
\1\4:\3\2\6

Pastings for "Character Translations"...
:,J,a,n=0,1
:,F,e,b=0,2
:,M,a,r=0,3
:,A,p,r=0,4
:,M,a,i=0,5
:,J,u,n=0,6
:,J,u,l=0,7
:,A,u,g=0,8
:,S,e,p=0,9
:,O,k,t=1,0
:,N,o,v=1,1
:,D,e,z=1,2
Luuk
 
Posts: 208
Joined: Fri Feb 21, 2020 10:58 pm

Re: Reformat the date in file names

Postby Adrian.Bradescu » Thu Jan 28, 2021 5:54 pm

Thank you so much Luuk.
I used the first comand you gave me as the last one didn't worked properly. I copied all my documents into another PC where I installed the most recent version of BRU and after changing the names, I copied back into my office laptop.
Thank you, you saved me for tens of hours of manual renaming.
All the Best !
Adrian.Bradescu
 
Posts: 3
Joined: Fri Jan 15, 2021 1:50 pm

Re: Reformat the date in file names

Postby free2flyph » Sat Mar 27, 2021 1:56 am

Hi, saw the code from RegexNinja and I tried. It did work except when the date is at 01-19-2020 and below. But when it is 01-20-2020 and up, it fails.

I tried this also when the month has two digits, its valid, but when it is only one digit, it did not work. So, the month must have two digits, right?

Ex: Abadi 5-04-2020 assumption.pdf --> doesn't work
Abadi 05-04-2020 assumption.pdf --> Abadi 2020-05-04
Abadi 05-20-2020 assumption.pdf --> doesn't work

Or do i need another regex to convert
Abadi 5-04-2020 assumption.pdf
to
Abadi 05-04-2020 assumption.pdf

Thanks for the help...
free2flyph
 
Posts: 3
Joined: Sat Mar 27, 2021 1:30 am

Convert 'm-dd-yyyy' -or- 'mm-dd-yyyy' ==> 'yyyy-mm-dd'

Postby Luuk » Sun Mar 28, 2021 4:04 am

Greetings Free2flyph. Im guessing you meant the colored-regex from RegexNinja?
Im almost said he just makes a typo, so then fixing the '[01]' into '[0123]'.

But then after studying, Im noticed that its to conduct dates like... dd-mm-yyyy.
And your example filenames do instead present the dates like...... mm-dd-yyyy.
So finally realized that '[01]' is to forbid months starting with '2' or higher.

Thanks for posting because Im trying to find this it forever, but only saved Page-3 in the bookmarks!
At first, Im trying to copy that format to only conduct dates like mm-dd-yyyy, but then realizing...
How can the regex know if "02-01" is really "Feb 01" or "Jan 02", lol.

This a good example why Im thinking its best to make a new post with example NowNames.ext ===> NewNames.ext
This way the users are not getting confused when others come with different request, but also making typos.

At first, 'FrequentlyPuzzled' says he wants to change the names like (filename)mm.dd.yyyy.
But since he is not posting NowNames.ext ===> NewNames.ext, he must re-explain this twice.
So then 'Hasse' is guessing five different regexs until finding the exact solution.

Then 'Mwsasser', 'Pepemendes', and 'Sandma85' come with more requests, but giving good examples.
So their solutions come quickly, but maybe confusing other users looking at the original post.

Then 'Jvanheck2' comes to request "Foto MM-DD-YYYY HH MM SS.jpg" ===> Foto YYYY-MM-DD HH MM SS.jpg
So 'Therube' quickly provides a solution, but then 'Jvanheck2' said he makes a mistake, and still not giving any examples.
Then saying he meant "Foto DD-MM-YYYY HH MM SS.jpeg" ===> "Foto MM-DD-YYYY HH MM SS.jpeg" but makes another mistake!
So really he needed: "Foto DD-MM-YYYY HH MM SS.jpeg" ===> "Foto YYYY-MM-DD HH MM SS.jpeg (no example, and forgets Foto).

But again with no examples, so then 'RegexNinja' also guessing different regexs for the latest request.
So then 'RegexNinja' presenting his own "Results", because 'Jvanheck2' never does provide any samples.
Im getting so confused, I must create many sample filenames, before finally understanding who is wanting what.

So if you already renamed with the colored-regex, Im really not know how to fix, except with also destroying others?
There should be an advanced regex to conduct the 'exact opposite', but so far Im not finding it anywhere.

If you want a 'v2' regex to convert 'm-dd-yyyy' or 'mm-dd-yyyy' ===> 'yyyy-mm-dd', the Match and Replace is like...
Code: Select all
(\b|_)(\d-\d\d-)(19|20)(\d\d)(\b|_)/g(?X)(\b|_)(\d\d-\d\d)-(19|20)(\d\d)(\b|_)/g
${1}0$2$3$4$5(?X)${1}$3$4-$2$5
But its not advanced, so never recognizing 'm-dd' from 'd-mm', or 'mm-dd' from 'dd-mm'.
Its just inserting '0' if needed, then rearranging the numbers like your explanation.
Luuk
 
Posts: 208
Joined: Fri Feb 21, 2020 10:58 pm

Re: Reformat the date in file names

Postby free2flyph » Mon Mar 29, 2021 4:50 pm

Thank you very much Luuk.

The [01] makes sense now to me. This limit the two digit if it is a month or days.

I tried also the 'm-dd-yyyy' or 'mm-dd-yyyy' ==> 'yyyy-mm-dd' code that you sent, but its not working on me. I am using the latest version of BRU and don't worry I am using it in a test folder so no files has been destroyed yet. :)

Again, thank you for that [01] to [0123] explanation.
free2flyph
 
Posts: 3
Joined: Sat Mar 27, 2021 1:30 am

Re: Reformat the date in file names

Postby free2flyph » Mon Mar 29, 2021 6:17 pm

Thank you Luuk, the code works perfectly. I forgot to select the 'v2'.
free2flyph
 
Posts: 3
Joined: Sat Mar 27, 2021 1:30 am

Previous

Return to Regular Expressions