Renaming image files with PyExifTool 0.5.4 (exiftool in python)

I’m trying to rename jpg files from a python script with exiftool using PyExifTool 0.5.4.
I can change tags, e.g. DateTimeOriginal, but when I try to rename files using tags I can’t get the correct formatting for the filename.

with exiftool.ExifToolHelper() as et:
    et.execute('-d %Y-%m.%%e', '-filename<DateTimeOriginal', os.path.join(subdir, file))

When called from python this code seems to ignore the format given with -d and simply renames files to the content of the DateTimeOriginal tag, e.g. 2021:12:25 16:26:37. The same result is produced when I run it in a terminal without '-d %Y-%m.%%e'

Running the command from the terminal, e.g. exiftool -d %Y%m.%%e '-filename<DateTimeOriginal' b.jpg renames the file using YYYYmm as expected.

Read more here: Source link