воскресенье, 28 мая 2023 г.

Set Photo "date taken" field as a file attributes(creation, modified, access)


import os, pathlib, exifread, time, datetime
from win32_setctime import setctime
for path in os.listdir('.'):
    if os.path.isfile(path) and pathlib.Path(path).suffix!='.py':
        with open(path, 'rb') as image:
            exif = exifread.process_file(image)
            try:
                crtdate = time.mktime(datetime.datetime.strptime(str(exif['EXIF DateTimeOriginal']), "%Y:%m:%d %H:%M:%S").timetuple())
                os.utime(path, (crtdate, crtdate))
                setctime(path, crtdate)
            except:
                print('hello')

Комментариев нет:

Отправить комментарий