ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: Exifdude on January 03, 2019, 04:56:02 PM

Title: Renaming JPGs with the DateTimeOriginal and SubSecTimeOriginal fields
Post by: Exifdude on January 03, 2019, 04:56:02 PM
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"
Title: Re: Renaming JPGs with the DateTimeOriginal and SubSecTimeOriginal fields
Post by: Phil Harvey on January 03, 2019, 06:54:30 PM
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
Title: Re: Renaming JPGs with the DateTimeOriginal and SubSecTimeOriginal fields
Post by: Exifdude on January 04, 2019, 05:09:44 PM
That worked perfectly thank you so much.