Renaming image files with PyExifTool 0.5.4

Started by dropf, November 04, 2022, 06:21:42 AM

Previous topic - Next topic

dropf

Hi guys, I already posted on stackoverflow 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.

Phil Harvey

Maybe try putting -d and %Y-%m.%%e as separate arguments in the execute() call.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

dropf

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.

Phil Harvey

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
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

bparks0263


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.