pythoncom and writing file "summary" info on Windows

M

mattleftbody

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.

so after various imports I try the following:

file=pythoncom.StgOpenStorageEx(fname, m, storagecon.STGFMT_FILE, 0 ,
pythoncom.IID_IPropertySetStorage)

summ=file.Create(pythoncom.FMTID_SummaryInformation,
pythoncom.IID_IPropertySetStorage,

storagecon.PROPSETFLAG_DEFAULT,
storagecon.STGM_READWRITE|storagecon.STGM_CREATE|
storagecon.STGM_SHARE_EXCLUSIVE)

everything seems fine so far, until I try and write which doesn't seem
to do anything. I tried the following three ways:

summ.WriteMultiple((storagecon.PIDSI_AUTHOR, storagecon.PIDSI_TITLE),
('Author', 'Title'))

summ.WriteMultiple((4,2 ), ('Author', 'Title'))

summ.WritePropertyNames((4,2 ), ('Author', 'Title'))


Any advice would be most appreciated!

Matt
 
T

Tim Golden

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,266
Messages
2,571,075
Members
48,772
Latest member
Backspace Studios

Latest Threads

Top