pythoncom and writing file "summary" info on Windows

Tim Golden mail at timgolden.me.uk
Mon Jun 8 17:19:30 EDT 2009


mattleftbody at gmail.com wrote:
> Hello,
> I was trying to put together a script that would write things like the
> Author and Title metadata fields of a file under Windows.  I got the
> win32 extensions installed and found a few things that look like they
> should work, though I'm not getting the result I would expect.
> Hopefully someone has worked through this area and can point me in the
> right direction.

FWIW, this works for me:

<code>
import os, sys
from win32com.shell import shell, shellcon
import pythoncom
from win32com import storagecon

filepath = sys.argv[1]
pidl, flags = shell.SHILCreateFromPath (os.path.abspath (filepath), 0)
property_set_storage = shell.SHGetDesktopFolder ().BindToStorage (
  pidl, None, pythoncom.IID_IPropertySetStorage
)
summary_info = property_set_storage.Open (
  pythoncom.FMTID_SummaryInformation, 
  storagecon.STGM_READWRITE | storagecon.STGM_SHARE_EXCLUSIVE
)
summary_info.WriteMultiple ([storagecon.PIDSI_TITLE], ["BLAHBLAH2"])
</code>


BUT... you need to be aware that working with files -- typically
media files such as JPEGs etc. -- can play strange tricks with
this info as they implement their own property handlers to
provide extra file-specific info.

On my system, for example, altho' the Summary tab offers
Title and Author and I can fill them in an Apply, nothing
happens. They're not there when I come back, and likewise
the code above won't affect them. Maybe this is what you're
seeing.

TJG



More information about the Python-list mailing list