将道具(标签/关键字)添加到文件夹中,仅使用Python 3中的CTYPE

发布于 2025-02-10 11:45:26 字数 1551 浏览 1 评论 0原文

我正在尝试使用Windows API将标签添加到文件夹中,并且我偶然发现了本文

在本文中

要创建一个ANSI简单属性集,您可以调用iPropertySetStorage ::创建以创建属性集,指定propsetflag_ansi(simple是默认类型的属性集合),然后用呼叫iPropertyStorage :: WriteMultiple来写入它。要读取属性集,您将调用iPropertyStorage :: readmultiple。

我尝试将其作为下面的代码进行操作,但要卡住,因为我找不到ipropertysetStorageipropertystorage is。

from ctypes import sizeof

STGM_READWRITE = 0x00000002

def addTag(folder):
    shell32 = ctypes.windll.shell32

    _clsid = None # should to be the CLSID from the SHFOLDERCUSTOMSETTINGS

    # ↓↓↓↓↓↓ I can't find where should I get IPropertySetStorage
    shell32.IPropertySetStorage.Create("{F29F85E0-4FF9-1068-AB91-08002B27B3D9}", _clsid, 0, STGM_READWRITE)

    rglpwstrName = ["TestTag"]
    rgpropid = ["prop5"]
    cpropid = sizeof(rgpropid)

    # ↓↓↓↓↓↓ I can't find where should I get IPropertyStorage
    shell32.IPropertyStorage.WritePropertyNames(cpropid, rgpropid, rglpwstrName)

addTag(r"C:\Users\Agustin\Desktop\New folder")

我尝试在此处和Microsoft文档中搜索答案Windows“标签”带有Python 3)是我见过的最接近的示例。那里的示例是使用pywin32,但是 我想找出仅使用ctypes 才能将其删除。

我的问题:在哪里可以找到ipropertysetstorageipropertystorage?以及如何仅使用 ctypes 的Windows API将标签添加到文件夹中。

任何帮助将不胜感激。

I'm trying to add tag to a folder using Windows API, and I've stumbled upon this article.

According in this article,

to create an ANSI simple property set, you would call IPropertySetStorage::Create to create the property set, specifying PROPSETFLAG_ANSI (simple is the default type of property set), then write to it with a call to IPropertyStorage::WriteMultiple. To read the property set, you would call IPropertyStorage::ReadMultiple.

I tried doing it as the code below but get stuck because I can't find where the IPropertySetStorage and IPropertyStorage is.

from ctypes import sizeof

STGM_READWRITE = 0x00000002

def addTag(folder):
    shell32 = ctypes.windll.shell32

    _clsid = None # should to be the CLSID from the SHFOLDERCUSTOMSETTINGS

    # ↓↓↓↓↓↓ I can't find where should I get IPropertySetStorage
    shell32.IPropertySetStorage.Create("{F29F85E0-4FF9-1068-AB91-08002B27B3D9}", _clsid, 0, STGM_READWRITE)

    rglpwstrName = ["TestTag"]
    rgpropid = ["prop5"]
    cpropid = sizeof(rgpropid)

    # ↓↓↓↓↓↓ I can't find where should I get IPropertyStorage
    shell32.IPropertyStorage.WritePropertyNames(cpropid, rgpropid, rglpwstrName)

addTag(r"C:\Users\Agustin\Desktop\New folder")

I tried searching for answers here and in the Microsoft documentation but (Reading and writing Windows "tags" with Python 3) is the closest example I've seen. The example there is using pywin32 but I want to find out if this can be pulled off using only ctypes.

My Question: Where can I find the IPropertySetStorage and IPropertyStorage? And how can I add tag to a folder using only the Windows API with ctypes.

Any help will be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文