5

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.

File Properties Window

The Description -> Tags property is what I want to read and write to a file.

2
  • The Description -> Tags property is what I want to read and write to a file. I want to read and write. Commented Aug 8, 2019 at 22:17
  • 1
    The windows "Tags" property for images is filled from three different metadata entries. XPKeywords, IPTC:Keywords, and XMP:Subject. XPKeywords is less common, mostly only supported by Windows. Most other programs will support IPTC:Keywords and/or XMP:Subject, usually keeping them in sync if it supports both (for example, Adobe Lightroom). One thing you might look into is PyExiftool which is a wrapper for exiftool Commented Aug 8, 2019 at 23:01

2 Answers 2

5

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.

Sign up to request clarification or add additional context in comments.

1 Comment

You are not using the Windows property system which is probably why they are not in sync. The property system is an abstraction layer on top of the specific properties in all kinds of file types.
0

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.

1 Comment

I don't disagree that the ghost file seems like a lockfile, but saying "when you open a file, Windows..." seems extremely broad, and is invalidated by a simple test. I copied a file, opened it in a variety of programs, and checked for lock files with Get-ChildItem (powershell). I looked for hidden files (-Hidden), too. Nothing can be seen. I have seen some programs create lockfiles, but they're usually implementation-specific, and not generally attributable to Windows, as you seem to say.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.