windows 如何使用 Python 访问文件元数据?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1512600/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 13:13:50  来源:igfitidea点击:

How to access file metadata with Python?

pythonwindowsmetadata

提问by Sid

I'm trying to write a program in python that retrieves and updates file metadata on windows. I've tried searching on Google regarding what modules to use but I haven't found anything very concrete or useful.

我正在尝试用 python 编写一个程序来检索和更新 Windows 上的文件元数据。我尝试在 Google 上搜索有关要使用的模块的信息,但没有找到任何非常具体或有用的信息。

Some people suggested the stat modulewhich can give you info such as file access and last modification. But I'm looking to retrieve other types of metadata available on Windows. For example tags, author, rating, artists etc.

有些人建议使用stat 模块,它可以为您提供诸如文件访问和最后修改等信息。但我希望检索 Windows 上可用的其他类型的元数据。例如标签、作者、评级、艺术家等。

How can I retrieve this information for a file using Python?

如何使用 Python 检索文件的此信息?

Thanks

谢谢

回答by Alex Martelli

Essentially as I said hereless than an hour ago,

基本上就像我不到一个小时前在这里所说的那样,

Apparently, you need to use the Windows Search API looking for System.Keywords -- you can access the API directly via ctypes, or indirectly (needing win32 extensions) through the API's COM Interop assembly. Sorry, I have no vista installation on which to check, but I hope these links are useful!

显然,您需要使用 Windows Search API 来查找 System.Keywords——您可以通过 ctypes 直接访问 API,或通过 API 的 COM Interop 程序集间接访问(需要 win32 扩展)。抱歉,我没有要检查的 vista 安装,但我希望这些链接有用!

Links don't preserve across copy and paste, please just visit the other SO questions for them;-).

链接不会通过复制和粘贴保留,请访问其他 SO 问题;-)。