Alternate Data Streams on a folder

2.7k views Asked by At

I'm using StgCreateStorageEx from python win32com based adapting the code in testStorage.py to write my own file_id attribute onto any file.

According to alternate-streams (though not necessarily from this API call) it should be possible to save to a directory/folder, but changing the flags yield different errors, eg:

from win32com import storagecon
import pythoncom, os, win32api

fname = r"c:\temp\test\test.txt" #works
fname = r"c:\temp\test\test2"

def testit():
    m=storagecon.STGM_READWRITE | storagecon.STGM_SHARE_EXCLUSIVE
    pss=pythoncom.StgOpenStorageEx(fname, m, storagecon.STGFMT_FILE, 0, pythoncom.IID_IPropertySetStorage)

results in:

pywintypes.com_error: (-2147024895, 'Incorrect function.', None, None)

EDIT: Any suggestions on how to get this to work from both WinXP, Win7 and Windows Server 2003/R2?

Note that the end result does not necessarily need to use this API, I just need to be able to do it efficiently from Python. By efficiently I mean not through many different technology layers.

2

There are 2 answers

5
Roger Upole On

It succeeds if storagecon.STGM_DIRECT is added to the mode.

0
RuiDC On

Looking at the results, StgOpenStorageEx adds a lot more to the file than simply writing to open(fname + ":stream_name"), so i've opted for that. Is there any downside to this compared to StgOpenStorageEx apart from not being able to write to the standard summary fields?