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

前端 未结 4 683
悲&欢浪女
悲&欢浪女 2020-11-30 12:23

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 loo

相关标签:
4条回答
  • 2020-11-30 12:47

    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!

    0 讨论(0)
  • 2020-11-30 12:49

    It appears that Windows stores the tags in the files. Just tag any image and open the image in notepad and look for something XML-like(RDF) and you will find your tag there. Well... now we know that they are indeed stored in the files, but we still have no idea how to manipulate them.

    But google is to the rescue. I googled: windows metadata api

    and found this: http://blogs.msdn.com/pix/archive/2006/12/06/photo-metadata-apis.aspx

    0 讨论(0)
  • 2020-11-30 12:49

    There are actually 2 different implentations of document properties (source).

    1. The COM implementation embeds them directly in the file itself : this is the approach used for Office documents for example. Tim Golden's code described on this page works well for these.

    2. On NTFS 5 (Win2k or later), you can add Summary info to any file, and it's stored in alternate data streams. I suppose the Windows Search API would work on these, but I have not tested it.

    0 讨论(0)
  • 2020-11-30 12:56

    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
    
    0 讨论(0)
提交回复
热议问题