Hi guys, I already posted on stackoverflow (https://stackoverflow.com/questions/74305074/renaming-image-files-with-pyexiftool-0-5-4-exiftool-in-python) but I guess it's a little too specialized, so I'm triying here too.
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.
Maybe try putting -d and %Y-%m.%%e as separate arguments in the execute() call.
- Phil
Thanks for the quick reply Harvey (and obviously the exiftool ;) )
Unfortunately no change and I'm at a loss since the same command works in a terminal. It must have something to do with the argument processing but I also don't know how to debug further.
There are a couple of ways to progress here. If you can see the console output from your exiftool command, you could use the -echo option to play with the arguments to be sure they are getting through properly.
Another idea would be to put your arguments in a file and use the -@ option to load them from the file instead of the command line. But of course that assumes that the -@ will work in your execute() call.
- Phil
Maybe it's a typo but the format string is different, in Python there is dash between %Y and %m, and not in the terminal command.