如何在 Windows 文件属性面板中访问标签属性? 有我可以使用的模块吗?大多数 Google 搜索都会产生与媒体文件、文件访问时间相关的属性,但与标签、描述等元数据属性关系不大。
exif
模块能够 access a lot more properties比我能找到的大多数内容都要多,但它仍然无法读取“标签”属性。
Description
-> Tags
属性是我想要读取和写入文件的属性。
最佳答案
有一个完整的模块专门用于我想要的: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 + '~')
我不太确定幽灵文件是什么或做什么,它看起来是原始文件的精确副本,因为文件大小保持不变,但无论如何,我将其删除,因为它对于完成读取完全没有用/写入我需要的元数据的用途。
在设置关键字时,我注意到一些奇怪的行为,比如有些被吞入文件中(文件大小发生了变化,我知道它们在那里,但 Windows 不承认这一点),并且仅手动删除关键字后,它们会突然重新出现吗?很奇怪。
关于python - 在Python中访问Windows文件 "Tags"元数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57421099/