Convert date from mm-dd-yy to yyyy-mm-dd in file name

A swapping-ground for Regular Expression syntax

Convert date from mm-dd-yy to yyyy-mm-dd in file name

Postby DaveApple1 » Wed Jan 14, 2015 4:51 pm

Good Day. I have hundreds of different files all with the date format of mm-dd-yy which I need to change to yyyy-mm-dd. The hard part is not all of the files have the date at the end of the file name. I have found a few example that partly cover this but none have worked correctly for me. Any help would be greatly appreciated.

Example:
file_04-14-12.pdf
file_04-14-12-signed.pdf
file_01-01-05.pdf
DaveApple1
 
Posts: 2
Joined: Sat Dec 03, 2011 5:51 pm

Rearrange swap date timestamp month day year

Postby Stefan » Wed Jan 14, 2015 5:15 pm

DaveApple1 wrote:Good Day. I have hundreds of different files all with the date format of mm-dd-yy which I need to change to yyyy-mm-dd. The hard part is not all of the files have the date at the end of the file name. I have found a few example that partly cover this but none have worked correctly for me. Any help would be greatly appreciated.

Example:
file_04-14-12.pdf
file_04-14-12-signed.pdf
file_01-01-05.pdf



Try

FROM:
file_04-14-12.pdf
file_06-23-12-signed.pdf
file_01-09-05.pdf

TO:
file_12-14-04.pdf
file_12-23-06-signed.pdf
file_05-09-01.pdf

RULE:
Convert date from mm-dd-yy to yyyy-mm-dd in file name


USE
RegEx(1)
Match:(.+_)(\d\d)(-\d\d-)(\d\d)(.*)?
Repla:\1\4\3\2\5


Add an additional rule:
Repl.(3)
Replace:\5
With:
to remove the redundant " \5"
(read http://www.bulkrenameutility.co.uk/forum/viewtopic.php?p=6272#p6272 for more)



 
Stefan
 
Posts: 736
Joined: Fri Mar 11, 2005 7:46 pm
Location: Germany, EU

Re: Convert date from mm-dd-yy to yyyy-mm-dd in file name

Postby gordobru » Sat Mar 21, 2015 5:00 pm

Hello, I am rather new to BRU, but I absolutely love it.
I tried using the expression detailed below, however, this converts to yy-dd-mm
It does NOT convert to yy-mm-dd and of course, not to yyyy-mm-dd

I too have been looking for the appropriate expression to change thousands of files on my server.
Through trial and error, I used the following:
RegEx (1)
Match: (.*)(\d\d)(-\d\d-)(\d\d)(.*)?
Replace: \120\4-\2\3\5

Examples FROM:
Axiom Black Cartridge Receipt 01-09-12.pdf
Calendars packing slip 09-29-11.pdf
Office Max Office Supplies 12-14-11.pdf
Postage Invoice 01-21-11.pdf
Staples shipping--5 red 3 ring binders 4 inch 11-12-11.pdf
OfficeMax Invoice A839266286 05-10-11.pdf
Discount School 2011-08-05 Supply Packing List.pdf

Examples BECOMES:
Axiom Black Cartridge Receipt 2012-01-09-.pdf
Calendars packing slip 2011-09-29-.pdf
Office Max Office Supplies 2011-12-14-.pdf
Postage Invoice 2011-01-21-.pdf
Staples shipping--5 red 3 ring binders 4 inch 2011-11-12-.pdf
OfficeMax Invoice A839266286 2011-05-10-.pdf
Discount School 202005-11-08- Supply Packing List.pdf WRONG of course

I need to get rid of the "-" dash at the end
Cheers,
G
gordobru
 
Posts: 2
Joined: Sat Feb 28, 2015 5:02 am

Convert swap rearrange sort reorder date mm-dd-yy

Postby Stefan » Tue Jun 16, 2015 6:46 am

gordobru wrote:I need to get rid of the "-" dash at the end


No need to have that dash at the end at first place.

Just don't capture the hyphen, match it only:

RegEx (1)
Match: (.*)(\d\d)(-\d\d-)(\d\d)(.*)? <<<< yours
Match: (.*)(\d\d)(-\d\d)-(\d\d)(.*)?
Replace: \120\4-\2\3\5




.
Stefan
 
Posts: 736
Joined: Fri Mar 11, 2005 7:46 pm
Location: Germany, EU


Return to Regular Expressions