gpt4 book ai didi

python - 文件夹上的备用数据流

转载 作者:太空宇宙 更新时间:2023-11-04 06:35:23 25 4
gpt4 key购买 nike

我正在使用基于 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 相比,这有什么缺点吗?

关于python - 文件夹上的备用数据流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12013450/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com