Reformat the date in file names

A swapping-ground for Regular Expression syntax

Reformat the date in file names

Postby FrequentlyPuzzled » Tue Aug 02, 2016 4:21 pm

I have many (thousands) of pdf files in multiple folders each containing a name with a date. I need to change the date format in the file name only: for example, from (file name) 02.03.2015.pdf to (same file name) 2015.02.03.pdf. And after each such change, to move the next file in the folder and do the same. If I could do the entire database recursively, and only change each date format, regardless of file name, that would be even better. Each file in a single folder has a different date in the name, although the original file name in each folder is the same. For example, in one folder, it might be Production (company) (date).pdf. Is there a way to accomplish this in the program? I am, unfortunately, not familiar with regex at all, and don't even know if it could help me. To change each file individually will not only take me months, it will introduce the possibility - or probability :roll: - of error. Any and all help would be greatly appreciated, even if it just tells me I need to look elsewhere.
FrequentlyPuzzled
 
Posts: 4
Joined: Tue Aug 02, 2016 3:53 pm

Re: Newbie needs help

Postby Hasse » Tue Aug 02, 2016 8:32 pm

I am not sure if company is always within parentesis or if the company name is always the same, but you can try this:
In my example below I have used different company names just in case they vary.

Under RegEx (1) on the left side of the BRU interface:

Match:
(.+)\((\d\d)\.(\d\d)\.(\d\d\d\d)

Replace:
\1 (\4.\3.\2)

Before change:
Production company1 (30.11.2015).pdf
Production company2 (02.03.2015).pdf
Production company3 (15.09.2015).pdf
Production company4 (02.10.2016).pdf
Production company5 (30.12.2014).pdf

After change:
Production company1 (2015.11.30).pdf
Production company2 (2015.03.02).pdf
Production company3 (2015.09.15).pdf
Production company4 (2016.10.02).pdf
Production company5 (2014.12.30).pdf

Try it in a testfolder, just to be on the safe side.
I hope it helps!

/Hasse
Hasse
 
Posts: 10
Joined: Sat Jul 16, 2016 4:52 pm

Re: Reformat the date in file names

Postby FrequentlyPuzzled » Wed Aug 03, 2016 6:39 pm

Hasse: Many thanks for such a swift response. Let me attempt to make my initial post clearer. Each file in a given folder has the same name followed by a date and none of which – name or date - are within parentheses. For example, in one folder, all files might be named Mobile Production 01.03.2015.pdf, Mobile Production 02.05.2015.pdf, throughout a year and continuing with the same name and date format for multiple years. My job is to get them so they will order themselves by date, such as 2015.01.03, 2015.02.02, etc.. As they now exist, multiple years can be intermixed when reviewing the folder, since they order on the first numbers ( the month in the current format) rather than the years followed by the month. Thus it is difficult to find a specific file, or to check if a file is missing for a given year. Ideally, of course, would be to both change the date and put it first, for example, from Mobile Production 01.03.2015.pdf to 2015.01.03 Mobile Production.pdf, but I am extremely happy at the moment just with the date format change as I believe you provided.

However, I was not successful and I assume it was some error on my part. As I understood your instructions, starting from the BRU screen, under RegEx (1), I did a copy and paste of the expression you provided for Match, and entered it where indicated. I did the same for the Replace expression. I made no other changes. I then opened a test folder and selected a few of the appropriate files to change, but the Rename button remained grayed out. I tested, and was able to make other changes, such as capitalization. However no RegEx worked and the button was grayed. I did note that in your Match expression there are 4 open parens, but only 3 closed. I did not know where or if it was necessary to match. While I tried several locations, the Rename button always remained grayed out.
FrequentlyPuzzled
 
Posts: 4
Joined: Tue Aug 02, 2016 3:53 pm

Re: Reformat the date in file names

Postby Hasse » Thu Aug 04, 2016 3:42 pm

In Sweden, where I live, we normally use the dateformat YYYY-MM-DD, but I guess you use MM.DD.YYYY instead.
Try this one and see if it works for you:

Match:
(.+)(\d{2})\.(\d{2})\.(\d{4})

Replace:
\4.\2.\3 \1


(there is a space before \1 in the replace part)
Hasse
 
Posts: 10
Joined: Sat Jul 16, 2016 4:52 pm

Re: Reformat the date in file names

Postby Hasse » Thu Aug 04, 2016 4:01 pm

... and make sure you have checked the checkbox for RegEx (1) in the user interface, if the Rename button is greyed out.
Hasse
 
Posts: 10
Joined: Sat Jul 16, 2016 4:52 pm

Re: Reformat the date in file names

Postby FrequentlyPuzzled » Thu Aug 04, 2016 5:27 pm

Hasse:

Wonderful! Many thanks. I am now 95% of the way there. After BRU makes the changes, there now is a space which occurs before the .pdf in the filename. By way of example, the original file is named Mobile Production 01.03.2015.pdf, but after the renaming, it becomes 2015.01.03 Mobile Production .pdf. While it may not be apparent in this context, there is a space before the .pdf. How do I avoid that? Everything else is exactly what I need, for which I am most grateful. The time this will save is enormous.
FrequentlyPuzzled
 
Posts: 4
Joined: Tue Aug 02, 2016 3:53 pm

Re: Reformat the date in file names

Postby Hasse » Thu Aug 04, 2016 6:10 pm

After my post I also noticed the space at the end of the new filename (before the .pdf).

I will try to figure out the reason for that, but in the meantime you can get rid of the space if you under Remove (5) in the user interface change Last n from 0 to 1 . Not the best solution, but the space before .pdf disappears :)

If you get it working, and all your folders have the same structure, you can select the parent folder, and under Filters (12) check Subfolders to save you the time of opening one folder at a time, but be careful and check the New Name in the interface before you press the Rename button.
Hasse
 
Posts: 10
Joined: Sat Jul 16, 2016 4:52 pm

Re: Reformat the date in file names

Postby Hasse » Thu Aug 04, 2016 6:55 pm

I think I have solved the issue with the space at the end of the new filename (before the .pdf) now.

If you, under Match, add a space after the first group, it seems to work.

(.+) (\d{2})\.(\d{2})\.(\d{4}) instead of
(.+)(\d{2})\.(\d{2})\.(\d{4})

If it works, there is no need for you to change Last n from 0 to 1.
Hasse
 
Posts: 10
Joined: Sat Jul 16, 2016 4:52 pm

Re: Reformat the date in file names

Postby FrequentlyPuzzled » Thu Aug 04, 2016 9:19 pm

Hasse:

Spot on! It now works perfectly. I very much appreciate your efforts in resolving my problem. And as I said in the beginning, I have no experience with regex, but after this demonstration, I intend to begin learning. That is truly amazing power.
FrequentlyPuzzled
 
Posts: 4
Joined: Tue Aug 02, 2016 3:53 pm

Re: Reformat the date in file names

Postby mwsasser » Tue Sep 06, 2016 3:50 pm

I've got a similar issue. Unfortunately I'm also horrible at regex.

My filenames look like:

05-27-2016_095636.*

But I'd like them to be this:

2016-05-27_095636.*

Recommendations?
mwsasser
 
Posts: 2
Joined: Tue Sep 06, 2016 3:43 pm

Re: Reformat the date in file names

Postby KenP » Tue Sep 06, 2016 4:29 pm

mwsasser wrote:I've got a similar issue. Unfortunately I'm also horrible at regex.

My filenames look like:

05-27-2016_095636.*

But I'd like them to be this:

2016-05-27_095636.*

Recommendations?

This should do it.

RegEx(1):
Match: (.*)-(\d{4})_(.*)
Replace: \2-\1_\3
KenP
 
Posts: 198
Joined: Sat Jul 30, 2016 11:25 am

Re: Reformat the date in file names

Postby mwsasser » Tue Sep 06, 2016 4:49 pm

That worked perfectly. Thanks!
mwsasser
 
Posts: 2
Joined: Tue Sep 06, 2016 3:43 pm

Re: Reformat the date in file names

Postby pepemendes » Fri Sep 30, 2016 5:56 pm

Hi,

I have a similar problem but thousands of my files names are like the following example:

Current requiered
26062015_1.pdf -- to -->2015-06-26_1.pdf
26062015_0002.pdf -- to -->2015-06-26_0002.pdf
26092016.pdf -- to -->2016-09-26.pdf
27052015_0001_1.pdf -- to -->2015-05-27_0001_1.pdf

This string works in some files but on a great part on the other it doesn't work correctly. I tested to change some things but was unable to perform the desired changes.

tested:
RegEx(1):
Match:(.*)(\d{4})
Replace: \2-\1

07102015_0001.pdf --> 0001-07102015_.pdf
31122015.pdf --> 2015-3112.pdf


Can you give me an insight.
Thanks in advance.
pepemendes
 
Posts: 2
Joined: Fri Sep 30, 2016 5:34 pm

Re: Reformat the date in file names

Postby KenP » Fri Sep 30, 2016 6:34 pm

@ pepemendes

This should do it.

RegEx (1)
Match: (\d{2})(\d{2})(\d{4})(.*)
Replace: \3-\2-\1\4
KenP
 
Posts: 198
Joined: Sat Jul 30, 2016 11:25 am

Re: Reformat the date in file names

Postby pepemendes » Mon Oct 03, 2016 2:54 pm

Thanks so much, it worked perfectly.

:)
pepemendes
 
Posts: 2
Joined: Fri Sep 30, 2016 5:34 pm


Return to Regular Expressions