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

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

Leave a Comment