Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
177 views
in Technique[技术] by (71.8m points)

How do you retrieve the tags of a file in a list with Python (Windows Vista)?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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. 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.

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

E.g.

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...