ExifTool Forum

ExifTool => Newbies => Topic started by: lnjustin on December 26, 2018, 10:12:07 PM

Title: Filename regular expression
Post by: lnjustin on December 26, 2018, 10:12:07 PM
I have files of the format:
20151002_1910_IMG_2454.jpg
The first part is YYYYMMDD and the second part is HHMM of the CreateDate. The last part after the underscore is the original filename. Well, what was once the original filename.

Now, I'd like to convert the filename to be more apparent as to what the filename parts are:
YYYY-MM-DD_at_HHhMMmSSs_{Last Part of current filename}.
I know i can do this with regular expressions, but i'm not sure how. I need to grab from the 15th character until the period before the extension, and insert that after the formatted Create Date. Can anyone help?
Something like this:

exiftool -d %Y-%m-%d_at_%Hh%Mm%Ss_${Filename?????}.%%e '-filename<CreateDate'

Not sure what to put for ${Filename???????}
Title: Re: Filename regular expression
Post by: Hayo Baan on December 27, 2018, 02:19:38 AM
You can't use $filename in the date format string, but this should give you what you want:
exiftool -d '%Y-%m-%d_at_%Hh%Mm%Ss' '-filename<${createdate}_${filename;s/.*_//;s/\..*//}' FILEsOrDirs
(on windows, change single quotes to double quotes)
Title: Re: Filename regular expression
Post by: lnjustin on December 27, 2018, 07:20:42 AM
Thanks. That looks close. But
20040123_1926_IMG_0002.JPG
is renamed to
2004-01-23_at_19h26m39s_0002

Needs the full original filename (IMG_0002) in it, not just the last part of it.
Title: Re: Filename regular expression
Post by: Phil Harvey on December 27, 2018, 08:32:18 AM
Just remove s/.*_//; from the filename formatting then (this removes all characters up to and including the underline).

- Phil
Title: Re: Filename regular expression
Post by: lnjustin on December 27, 2018, 09:55:34 AM
Still struggling at this since I'm afraid the above suggestions didn't work. I need to capture everything starting from the 15th character (any type) up until right before the period for the extension. That's what I want to add onto the newly formatted create date portion of the new file name.

20040123_1926_IMG_0002.JPG
Should be renamed to
2004-01-23_at_19h26m39s_IMG_0002.JPG

But the IMG_0002 portion could be anything
Title: Re: Filename regular expression
Post by: StarGeek on December 27, 2018, 11:56:45 AM
Try '-filename<${createdate}_${filename;s/.{14}//}'

That will remove the first 14 characters.
Title: Re: Filename regular expression
Post by: lnjustin on December 27, 2018, 12:24:35 PM
That worked. Thanks!
Title: Re: Filename regular expression
Post by: Phil Harvey on December 28, 2018, 08:47:02 AM
Thanks StarGeek.  I didn't read carefully enough.

- Phil