I have some photos that were taken in a different timezone from what is needed. I need to convert the existing date taken value to be 5 hours earlier. I have some code below, but I'm unsure how to read each file's 'date taken' attribute and then subtract 5 hours from that. I thought that I could use exif to process this, like below. Im not sure how to know which format the date is stored in, or how to actually write the new date value to the 'date taken' field.
import os
import glob
from exif import Image
rootdir = r'C:\Users\Me\Desktop\test_dir'
#18,000 seconds = 5 hours
for subdir, dirs, files in os.walk(rootdir):
for file in files:
if file.endswith(".jpg") or file.endswith(".jpeg"):
old_time = file.datetime
new_time = old_time - 18000
#not sure how to write new_time to the date taken attribute
file.write(file.new_time)
else:
continue
I saw that there is another way to do with with bash, which is preferred since this task will be scheduled. but I couldnt find jhead once installed. My machine would run the jhead.exe, but would recognize it when calling it from the command line.
shopt -s nullglob
for dir in C:\Users\Me\Desktop\test_dir*/
do
for file in "$dir"/*
do
if f in *.jpg
then
jhead -ta-0:05:00 *.jpg
fi
done
done
pause
edited for syntax