IPTCInfo usage problem

Hi
I am a very new to Python so this question might be silly. I am trying to code a script which goes through the directory tree and when it finds a .jpg file it copies the individual words in the filename as a keywords (~tags) into the file. I managed to do this ok but somehow I get dublicate files created. The new files have .jpg~ ending so I assume they are some kind of temp files? According to docs/examples I found from net the save() function should save the IPTCInfo into the same file where it was read. What I do wrong here. My script below. Thanks for info!

import os
import iptcinfo3

for root, dirs, files in os.walk("."):
for name in files:
if(name.endswith((’.jpg’, ‘.JPG’))):
tags = name[:-4].split()
info = iptcinfo3.IPTCInfo(name, force=True)
for t in tags:
info[‘keywords’].append(t)

        info.save()

I don’t think you are doing anything wrong.

I can’t find much documentation for the iptcinfo3 project, but I found
the source code for the save method, and it looks like when you save a
file, it makes a backup copy of the original with a “~” tilde appended
to the name.

So my guess is that when you have a file “hello.jpg”, and you add some
tags, you get “hello.jpg” with the tags and the original backed up under
“hello.jpg~”.

If you don’t want the previous version to remain, it looks like you might be able to provide an “options” container to save. I haven’t tried this, but it might be possible to do:

    info.save(options=["overwrite"])

Hi
Thanks for your replies, helped a lot and gave confidence. My actual solution was to tweak a bit the source code of the IPTCInfo3 not to save the backup. Just commenting out two lines and everything worked ok :slight_smile: