如何使用 Python (Windows Vista) 检索列表中文件的标签? [英] How do you retrieve the tags of a file in a list with Python (Windows Vista)?

查看:30
本文介绍了如何使用 Python (Windows Vista) 检索列表中文件的标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为我拥有的各种文件夹制作一些标签云,但不幸的是,我似乎找不到在 Windows Vista 中访问文件标签的方法.我尝试查看 win32 模块和 os.stat,但似乎找不到方法.我可以得到一些帮助吗?

I want to make something of a tag cloud for various folders I have, but unfortunately, I can't seem to find a way to access the tags of a file in Windows Vista. I tried looking at the win32 module, and os.stat, but I can't seem to find a way. Can I get some help on this?

推荐答案

我使用了 win32 扩展包,以及我找到的一些演示代码.我在 这个线程.我不想在这里全部复制,但这里是简短的版本(点击前面的链接了解详细信息).

I went about it with the win32 extensions package, along with some demo code I found. I posted a detailed explanation of the process on this thread. I don't want to reproduce it all here, but here is the short version (click the foregoing link for the details).

  1. 下载并安装 pywin32 扩展程序.
  2. 获取 代码 Tim Golden 为就是这个任务.
  3. 将 Tim 的代码作为模块保存在您自己的计算机上.
  4. 调用新模块的 property_sets 方法(提供必要的文件路径).该方法返回一个可迭代的生成器对象.请参阅以下示例代码和输出.
  1. Download and install the pywin32 extension.
  2. Grab the code Tim Golden wrote for this very task.
  3. Save Tim's code as a module on your own computer.
  4. Call the property_sets method of your new module (supplying the necessary filepath). The method returns a generator object, which is iterable. See the following example code and output.

(至少在 XP 中这对我有用.)

(This works for me in XP, at least.)

例如

import your_new_module
propgenerator= your_new_module.property_sets('[your file path]')
    for name, properties in propgenerator:
        print name
        for k, v in properties.items ():
            print "  ", k, "=>", v

上述代码的输出将如下所示:

The output of the above code will be something like the following:

DocSummaryInformation
   PIDDSI_CATEGORY => qux
SummaryInformation
   PIDSI_TITLE => foo
   PIDSI_COMMENTS => flam
   PIDSI_AUTHOR => baz
   PIDSI_KEYWORDS => flim
   PIDSI_SUBJECT => bar

这篇关于如何使用 Python (Windows Vista) 检索列表中文件的标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆