我正在使用基于 python win32com 的 StgCreateStorageEx 调整 testStorage.py 中的代码将我自己的 file_id 属性写入任何文件。
根据 alternate-streams (虽然不一定来自此 API 调用)应该可以保存到目录/文件夹,但更改标志会产生不同的错误,例如:
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)
结果:
pywintypes.com_error: (-2147024895, 'Incorrect function.', None, None)
编辑: 关于如何使它在 WinXP、Win7 和 Windows Server 2003/R2 上工作的任何建议?
请注意,最终结果不一定需要使用此 API,我只需要能够从 Python 高效地完成即可。我所说的高效是指不通过许多不同的技术层。
请您参考如下方法:
查看结果,StgOpenStorageEx 向文件添加的内容比简单地写入 open(fname + ":stream_name") 多得多,所以我选择了它。除了不能写入标准摘要字段之外,与 StgOpenStorageEx 相比,这有什么缺点吗?
