Filename regular expression

Started by lnjustin, December 26, 2018, 10:12:07 PM

Previous topic - Next topic

lnjustin

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???????}

Hayo Baan

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)
Hayo Baan – Photography
Web: www.hayobaan.nl

lnjustin

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.

Phil Harvey

Just remove s/.*_//; from the filename formatting then (this removes all characters up to and including the underline).

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

lnjustin

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

StarGeek

Try '-filename<${createdate}_${filename;s/.{14}//}'

That will remove the first 14 characters.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

lnjustin


Phil Harvey

Thanks StarGeek.  I didn't read carefully enough.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).