How to rename specific parts of a filename

Post any Bulk Rename Utility support requirements here. Open to all registered users.

How to rename specific parts of a filename

Postby uraniumbreather » Tue Oct 10, 2017 12:15 pm

I have files that are saved differently.
Let me give you examples of the file names:

2014-08-03_04-54-24

Another file in the same folder:

2014-09-01 at 00.15.46

Yet another file in the same folder (note the space in between the date and time):

2016-05-30 01_46_04

I have over 4,000 of these files.

I want them all renamed as per the second example 'YYYY-MM-DD at HH.MM.SS'. (HH= Hour, MM= Minutes, SS= Seconds), while obviously keeping each files individual date and time stamp.

How can I do this?

Many thanks
uraniumbreather
 
Posts: 20
Joined: Tue Oct 10, 2017 11:54 am

Re: How to rename specific parts of a filename

Postby KenP » Tue Oct 10, 2017 12:46 pm

This will rename the files in the format you want.

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

Re: How to rename specific parts of a filename

Postby uraniumbreather » Tue Oct 10, 2017 12:58 pm

I will try this as soon as I can.

Thank you

In the mean time can you please explain how that works so that I can make my own in the future?
uraniumbreather
 
Posts: 20
Joined: Tue Oct 10, 2017 11:54 am

Re: How to rename specific parts of a filename

Postby Admin » Tue Oct 10, 2017 1:19 pm

Admin
Site Admin
 
Posts: 1465
Joined: Tue Mar 08, 2005 8:39 pm

Re: How to rename specific parts of a filename

Postby uraniumbreather » Tue Oct 10, 2017 1:25 pm

It all goes over my head (had quick skim through).

Does what you gave me edit both with the underscore and with the space (the other 2 examples given)?
uraniumbreather
 
Posts: 20
Joined: Tue Oct 10, 2017 11:54 am

Re: How to rename specific parts of a filename

Postby KenP » Tue Oct 10, 2017 1:38 pm

uraniumbreather wrote:Does what you gave me edit both with the underscore and with the space (the other 2 examples given)?

Yes it will do exactly what you asked, before posting I tried it with the 3 examples you gave and it worked fine.

Regex can take a while to get your head around but like everything it gets easier with practice.
KenP
 
Posts: 193
Joined: Sat Jul 30, 2016 11:25 am

Re: How to rename specific parts of a filename

Postby uraniumbreather » Wed Oct 11, 2017 5:08 am

Slight issue with it.

Some of the files have an additional number at the end. Such as:

2016-07-04 at 13.45.28 1.png (some of the files are jpg (they vary).

The software adds the 1 in the case where a file was created within the same second so it has to give it a separating identifier.

The current expression removes the '1' which will cause a conflict as there is another file per file wth the '1', with the same name.

Some have a '2' or even '3' depending on how many files were created within the same second. I suppose there is potential for there to be even a '4' or '5'.

Any ideas on what to do because the expression you gave me (which works great thanks) is hindered by this.

Also additional number at the end can happen in any type of file naming, such as the one with the space or the one with the underscore.

Additionally sometimes the software creates the filename with a -abcdefg (where abcdefg is the name it gives it (for example it could be called -YouTube or -CCI28012015_0001 - Windows Photo Viewer.

There can also be an additional name at the start, before the year.

How can I get rid of the -abcdefg and the name at the start as well if I want to?

Thank you so much
uraniumbreather
 
Posts: 20
Joined: Tue Oct 10, 2017 11:54 am

Re: How to rename specific parts of a filename

Postby KenP » Wed Oct 11, 2017 9:53 am

This will include a space and a single digit after the time where there is one.

RegEx (1)
Match: ^.*(\d{4}-\d{2}-\d{2}).*(\d{2}).*(\d{2}).*((\d{2}\s\d)|(\d{2}))
Replace: \1 at \2.\3.\4

Anything before the 4 digit year will not be included in the new name, likewise apart from a space and a single digit (where they exist) anything after the time will not be included in the new name.

This seems to do the trick, but check the new names carefully before renaming in case I've missed anything.
KenP
 
Posts: 193
Joined: Sat Jul 30, 2016 11:25 am

Re: How to rename specific parts of a filename

Postby uraniumbreather » Wed Oct 11, 2017 11:31 am

Doesn't work on files with names like these:

Screen Shot 2014-08-26 at 20.39.47 - Windows Photo Viewer_2015-04-06_18-13-17

Greenshot_2014-12-11_02-52-58 - Windows Photo Viewer_2015-10-18_02-44-22

Any ideas.

It is resulting in selecting the second date (2015).
uraniumbreather
 
Posts: 20
Joined: Tue Oct 10, 2017 11:54 am

Re: How to rename specific parts of a filename

Postby KenP » Wed Oct 11, 2017 2:34 pm

Rename them separately.

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

Re: How to rename specific parts of a filename

Postby uraniumbreather » Wed Oct 11, 2017 3:21 pm

Rename what separately?
uraniumbreather
 
Posts: 20
Joined: Tue Oct 10, 2017 11:54 am

Re: How to rename specific parts of a filename

Postby KenP » Wed Oct 11, 2017 4:04 pm

uraniumbreather wrote:Doesn't work on files with names like these:

Screen Shot 2014-08-26 at 20.39.47 - Windows Photo Viewer_2015-04-06_18-13-17

Greenshot_2014-12-11_02-52-58 - Windows Photo Viewer_2015-10-18_02-44-22

Any ideas.

KenP wrote:Rename them separately.

RegEx (1)
Match: (\d{4}-\d{2}-\d{2}).*(\d{2}).*(\d{2}).*((\d{2}\s\d)|(\d{2})).*\d{4}
Replace: \1 at \2.\3.\4

uraniumbreather wrote:Rename what separately?

The files with 2 dates where the first one is the one you want to keep, as in your previous post.
KenP
 
Posts: 193
Joined: Sat Jul 30, 2016 11:25 am

Re: How to rename specific parts of a filename

Postby uraniumbreather » Wed Oct 11, 2017 8:06 pm

Oh you mean to say move the files with two dates in them into a different folder and then use the Regex you just gave?
uraniumbreather
 
Posts: 20
Joined: Tue Oct 10, 2017 11:54 am

Re: How to rename specific parts of a filename

Postby KenP » Thu Oct 12, 2017 1:01 am

I should have explained better, there's no need to move any files.

Use the code for the rile names with 2 dates first, select all the files and only the file names with 2 dates and will be affected.
Match: (\d{4}-\d{2}-\d{2}).*(\d{2}).*(\d{2}).*((\d{2}\s\d)|(\d{2})).*\d{4}
    This is the code for file names with 2 dates.



After you've renamed the files with 2 dates rename the files with only 1 date, file names that have already been renamed will not be affected.
Match: ^.*(\d{4}-\d{2}-\d{2}).*(\d{2}).*(\d{2}).*((\d{2}\s\d)|(\d{2}))
    This is the code for file names with just 1 date and time.
KenP
 
Posts: 193
Joined: Sat Jul 30, 2016 11:25 am

Re: How to rename specific parts of a filename

Postby uraniumbreather » Fri Oct 13, 2017 7:40 pm

Thank you. As soon as I get the time I will test this.
uraniumbreather
 
Posts: 20
Joined: Tue Oct 10, 2017 11:54 am

Next

Return to BRU Support