Shifting timestamp and renaming file in single command

Started by duttonbay, September 13, 2019, 05:10:03 AM

Previous topic - Next topic

duttonbay

I've been using exiftool for a little while, most commonly to either rename files to a YYYYMMDD-HHMMSS filename based on the create date, or to adjust the timestamps because I have changed timezones. I can do both in two steps like this:

exiftool -time:all+=1 -d %Y%m%d-%H%M%S.%%e blah.jpg
exiftool "-filename<createdate" -d %Y%m%d-%H%M%S.%%e "-filemodifydate<createdate" blah.jpg

but it would be very nice to be able to do this in a single step process. I've tried all sorts of options, read what seems like hundreds of posts in the forum, but haven't yet been able to get a single command to change the timestamps and also rename the file.

As you can probably see from the commands above I am using Windows.

Any help gratefully accepted.

Hayo Baan

This is what the -execute option is for:

exiftool -time:all+=1 -d %Y%m%d-%H%M%S.%%e -execute "-filename<createdate" -d %Y%m%d-%H%M%S.%%e "-filemodifydate<createdate" -common_args blah.jpg
Hayo Baan – Photography
Web: www.hayobaan.nl

duttonbay

Thanks Hayo. Right at the moment I am not in a position to try this, but will do so tomorrow morning (my time, in Australia)

StarGeek

Just to be clear, this is still a two pass solution.  The -execute option just speeds things up a bit because exiftool doesn't have to start up again. 

I'd suggest this
exiftool -globalTimeShift 1 -d %Y%m%d-%H%M%S.%%e -TagsFromFile @ -time:all "-filename<createdate" blah.jpg

Example output:
C:\>exiftool -time:all --system:all -g1 -a -s "Y:\!temp\yyy\blah.jpg"
---- ExifIFD ----
DateTimeOriginal                : 2019:08:01 13:00:00
CreateDate                      : 2019:08:01 13:00:00

C:\>exiftool -P -overwrite_original -globalTimeShift 1 -d %Y%m%d-%H%M%S.%%e -TagsFromFile @ -time:all "-filename<createdate" "Y:\!temp\yyy\blah.jpg"
    1 image files updated

C:\>exiftool -time:all --system:all -g1 -a -s "Y:\!temp\yyy"
======== Y:/!temp/yyy/20190801-140000.jpg
---- ExifIFD ----
DateTimeOriginal                : 2019:08:01 14:00:00
CreateDate                      : 2019:08:01 14:00:00
    1 directories scanned
    1 image files read
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

Hayo Baan

Thanks StarGeek for improving upon my proposal. Totally forgot about -globalTimeShift ::)
Adding -P to keep original file (modification) times is good too. And -overwrite_original is, of course, a necessary addition as well (once the command is verified to work well).
Hayo Baan – Photography
Web: www.hayobaan.nl

StarGeek

It's not something I really use so I wasn't sure it would work until I tested it.  I tried searching the forums for a shift and rename question and didn't find anything right away, though I was pretty sure it had come up before.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

duttonbay

Thanks both Hayo and StarGeek. StarGeek's solution worked perfectly, and I was able to modify it changer the filecreate and filemodify times as well, and with an -if condition, do this only for photos with the camera which had not been set to the current timezone.   I had searched for shift and rename too, and didn't find anything obvious, at least not quickly.