Hi Phil,
I'm a new user (and instant fan!) of exiftool. Thanks very much for the time you put into this great program.
I'd like to rename my image files by prefixing them with a timestamp including time zone. I've already added the time zone to the DateTimeOriginal EXIF tags (understanding it is non-standard) using the following command:
exiftool -progress "-AllDates#<${DateTimeOriginal}+12:00" .
Other images have been processed with different timezones, so now I have a folder containing all my images with various timezones.
Now I would like to rename them with the timestamp as a prefix. e.g.
DSCF4152.JPG
becomes:
20130929_175447+1200_DSCF4152.jpg
The command that theoretically should do this is:
exiftool -progress "-filename<${DateTimeOriginal}_%f.%le" -d %Y%m%d_%H%M%S%z .
There are however two problems with the %z pattern:
1. It returns the current system time zone instead of the timezone from the DateTimeOriginal tag.
2. It returns the full description of the timezone, the same as %Z, instead of the hours format specified in the perl strftime documentation
Here is an example to demonstrate both problems:
exiftool -s -DateTimeOriginal# -DateTimeOriginal -d %z DSCF4152.JPG
DateTimeOriginal : 2013:09:29 17:54:47+12:00
DateTimeOriginal : AUS Eastern Summer Time
The expected output on the second line is +1200
As you can see, the output is showing "AUS Eastern Summer Time" which is my current system timezone (UTC+11), not the timestamp's timezone UTC+12.
Any idea why the %z pattern isn't working properly, or what I could do as a workaround?
Thanks
Martin
Windows 8.0, ExifTool v9.40
Hi Martin,
Yes, the time zones don't work the way you want in the -d formatting. Instead, you could manually reformat DateTimeOriginal, like this:
"-filename<${DateTimeOriginal}${DateTimeOriginal#;s/.*([-+]\d+):(\d+)/$1$2/ or $_=''}_%f.%le" -d %Y%m%d_%H%M%S
The tricky things here are:
1) Must start with the "numerical" date/time value DateTimeOriginal#
2) I put in an "or" alternative for the case where the time zone doesn't exist. Otherwise you'd get the full date/time value here (colons and all), which would be bad.
- Phil
Thanks Phil, this works perfectly.
It's a pity the %z token doesn't work in the pattern. Is that a perl bug or is it because the time zone doesn't actually get read from the field? It would be handy for other users if your code could work around the problem and make it work as it should, whatever the cause is.
For the benefit of others, here is an example command to display just the timezone from the DateTimeOriginal field:
exiftool -p "${DateTimeOriginal#;s/.*([-+]\d+):(\d+)/$1$2/ or $_=''}" filename.jpg
The output for DateTimeOriginal value 2013:09:29 17:54:47+12:00 is "+1200".
Cheers
Martin
Hi Martin,
The Perl strftime function that does the date/time formatting doesn't even accept a timezone input, which is in line with the original form of this function in the C library. Checking now, it looks as if a time zone offset has been added to the time structure in modern C implementations, but it seems that Perl doesn't support this.
- Phil