Reputation: 750
How do I access the tags attribute here in the Windows File Properties panel? Are there any modules I can use? Most google searches yield properties related to media files, file access times, but not much related to metadata properties like Tags, Description etc.
the exif
module was able to access a lot more properties than most of what I've been able to find, but still, it wasn't able to read the 'Tags' property.
The Description
-> Tags
property is what I want to read and write to a file.
Upvotes: 5
Views: 7650
Reputation: 9
The weird ghost file you refer to is the Windows lock file. When you open a file, Windows automatically creates a file ~lock.filename. When you close the file, in all apps, windows removes this file. You can see this for yourself by opening a folder in file explorer then opening a file in that folder. The ~lock.filename will appear. Close the file and it will disappear.
Upvotes: 0
Reputation: 750
There's an entire module dedicated to exactly what I wanted: IPTCInfo3.
import iptcinfo3, os, sys, random, string
# Random string gennerator
rnd = lambda length=3 : ''.join(random.choices(list(string.ascii_letters), k=length))
# Path to the file, open a IPTCInfo object
path = os.path.join(sys.path[0], 'DSC_7960.jpg')
info = iptcinfo3.IPTCInfo(path)
# Show the keywords
print(info['keywords'])
# Add a keyword and save
info['keywords'] = [rnd()]
info.save()
# Remove the weird ghost file created after saving
os.remove(path + '~')
I'm not particularly sure what the ghost file is or does, it looks to be an exact copy of the original file since the file size remains the same, but regardless, I remove it since it's completely useless to fulfilling the read/write purposes of metadata I need.
There have been some weird behaviours I've noticed while setting the keywords, like some get swallowed up into the file (the file size changed, I know they're there, but Windows doesn't acknowledge this), and only after manually deleting the keywords do they reappear suddenly. Very strange.
Upvotes: 5