Renaming JPGs with the DateTimeOriginal and SubSecTimeOriginal fields

Started by Exifdude, January 03, 2019, 04:56:02 PM

Previous topic - Next topic

Exifdude

Need help in finding the right commands to rename JPGs in the following format based off of the DateTimeOriginal and if it's in Exif, the SubSecTimeOriginal at the end of the file name.
Filename would mimic the Android naming convention, i.e. YYYYMMDD_HHMMSSsss with sss being the 3 digit sub second value.  If the SubSecTimeOriginal field does not exist I would like it to default to 000.
I copied the below command from an example I found in the documentation but I'm not familiar enough with the commands to tweak it into what I'd like it to do if indeed that is at all possible.
exiftool -d %Y%m%d_%H%M%%-c.%%e "-filename<DateTimeOriginal"

Phil Harvey

Try this:

exiftool -d %Y%m%d_%H%M%S "-testname<${DateTimeOriginal}000%-c.%e" "-testname<${SubSecDateTimeOriginal}${SubSecDateTimeOriginal#;$_ = /(\.\d+)/ ? sprintf('%.3d',$1*1000) : '000'}%-c.%e" DIR

Here I have used an advanced formatting expression to parse the sub seconds of SubSecDateTimeOriginal, and if that tag doesn't exist the command falls back to use DateTimeOriginal.

I don't have time to test this, but it stands a chance of working.  Change "testname" to "filename" once you have it doing what you want.

- 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 ($).

Exifdude