[python-win32] PyWin32 API

Tim Roberts timr at probo.com
Thu Oct 19 19:58:57 EDT 2017


Josh Clayton wrote:
>
> I've been reading the documentation and had a question. 
>
> How would I create a custom tag in the details tab of a file then set
> it, and read it?
>
> If creating it is not possible, would it then be possible just set an
> already existing tag and then read it? My end goal is to try and
> metatag a large group of files to avoid having to open them to read
> them.  I'd rather just use a script to blast through 10,000 files and
> understand what files are in my folder structure.

The answer is quite complicated.

The Details tab in Explorer is exposing whatever metadata the underlying
file format supports.  If you look at a JPG, for example, the JPG format
has the ability to add "tags".  If you change the tag list while you're
looking at that tab, Windows modifies the file to add that to the tag
list in the JPG file.  Similar, a Word document supports metadata like
"DocTitle" and "Author", and Explorer understand the Word file format
and how to modify it.  There is no generic "hidden store" for these
properties.

You can get access to these properties using the Shell object model. 
Theoretically, this should do it, but this returned "None" for all of
the properties I tried.  I wish you luck.  If Tim Golden is listening,
he may have a better idea.

Note that the Shell.NameSpace API is one of the very few places in
Windows where the path MUST be specified with backslashes.  It will not
accept forward slashes.

    from win32com.client import Dispatch
    shell = Dispatch("Shell.Application")
    y = shell.NameSpace(r"c:\tmp\pvt")
    print( y.Title )
    for z in y.Items():
        print( z.Path )
        print( z.ExtendedProperty("Author"),
                z.ExtendedProperty("Date"),
                z.ExtendedProperty("Tags"))

-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



More information about the python-win32 mailing list