Page 1 of 2

How to rename specific parts of a filename

PostPosted: Tue Oct 10, 2017 12:15 pm
by uraniumbreather
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

Re: How to rename specific parts of a filename

PostPosted: Tue Oct 10, 2017 12:46 pm
by KenP
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

Re: How to rename specific parts of a filename

PostPosted: Tue Oct 10, 2017 12:58 pm
by uraniumbreather
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?

Re: How to rename specific parts of a filename

PostPosted: Tue Oct 10, 2017 1:19 pm
by Admin

Re: How to rename specific parts of a filename

PostPosted: Tue Oct 10, 2017 1:25 pm
by uraniumbreather
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)?

Re: How to rename specific parts of a filename

PostPosted: Tue Oct 10, 2017 1:38 pm
by KenP
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.

Re: How to rename specific parts of a filename

PostPosted: Wed Oct 11, 2017 5:08 am
by uraniumbreather
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

Re: How to rename specific parts of a filename

PostPosted: Wed Oct 11, 2017 9:53 am
by KenP
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.

Re: How to rename specific parts of a filename

PostPosted: Wed Oct 11, 2017 11:31 am
by uraniumbreather
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).

Re: How to rename specific parts of a filename

PostPosted: Wed Oct 11, 2017 2:34 pm
by KenP
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

Re: How to rename specific parts of a filename

PostPosted: Wed Oct 11, 2017 3:21 pm
by uraniumbreather
Rename what separately?

Re: How to rename specific parts of a filename

PostPosted: Wed Oct 11, 2017 4:04 pm
by KenP
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.

Re: How to rename specific parts of a filename

PostPosted: Wed Oct 11, 2017 8:06 pm
by uraniumbreather
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?

Re: How to rename specific parts of a filename

PostPosted: Thu Oct 12, 2017 1:01 am
by KenP
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.

Re: How to rename specific parts of a filename

PostPosted: Fri Oct 13, 2017 7:40 pm
by uraniumbreather
Thank you. As soon as I get the time I will test this.