0

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.

1 Answer 1

0

dropf, your call to execute() is incorrect. The parameter '-d %Y-%m.%%e' needs to be two different parameters to ExifToolHelper.execute()

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

This is the way that execute() works. If you have an unquoted space on your command line to exiftool, then you need to pass it as another parameter.

FYI: you can also post an issue onto the PyExifTool GitHub page if you have other issues

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.