如何使用GetDefaultFolder获取特定文件夹并删除其创建的不需要的文件夹 [英] How to get a specific folder with GetDefaultFolder and delete unneeded folders that it has created
问题描述
我试图弄清楚如何使用Python程序访问文件夹(请参见 SO答案.)我跑了:
I was trying to figure out how to access my folders with a Python program (see this SO answer.) When I ran this:
outlook = win32com.client.Dispatch("Outlook.Application")
namespace = outlook.GetNamespace("MAPI")
for i in range(50):
try:print(i,namespace.GetDefaultFolder(i).Name)
except:pass
以上程序显示或创建了一些我无法弄清楚如何删除的文件夹,例如:
The above program revealed or created some folders that I cannot figure out how to delete, such as:
-
Reminders
-
the file so that changes to the file will be reflected in your item.
-
RSS Subscriptions
Reminders
the file so that changes to the file will be reflected in your item.
RSS Subscriptions
除了无法删除这些文件夹外,我实际上还没有找到我正在以编程方式查找的文件夹.在Outlook中,我创建的文件夹与收件箱",已发送邮件"等处于同一级别...但是我不知道如何访问这些文件夹的父文件夹.
In addition to being unable to delete these folders, I still haven't actually found the folders I'm looking for programmatically. In Outlook, I have folders that I have created that are at the same level as Inbox, Sent Items, etc... but I don't know how to access the parent folder of these.
我的文件夹结构:
- ▼我的电子邮件地址
- 收件箱
- 草稿
- 已发送邮件
- ...
- 我要查找的文件夹
- ...
- 文件,以便对该文件所做的更改将反映在您的项目中.
- 提醒
- RSS订阅
- 搜索文件夹
- ▼ My email address
- Inbox
- Drafts
- Sent Items
- ...
- Folder I want to find
- ...
- the file so that changes to the file will be reflected in your item.
- Reminders
- RSS Subscriptions
- Search Folders
推荐答案
GetDefaultFolder
's argument is a enumeration. You can either use a numeric value that's courteously given in the doc,,或者根据在Excel中访问枚举常量使用Python和win32com 的COM,通过符号值访问它:
or, as per Accessing enumaration constants in Excel COM using Python and win32com , access it via the symbolic value:
#need to only do this once per machine; after that, a regular Dispatch will do o = win32com.client.gencache.EnsureDispatch("Outlook.Application") from win32com.client import constants o.GetDefaultFolder(constants.olFolderContacts)
如您所见,访问尚不存在的默认文件夹将创建它.参见例如如何隐藏或删除Outlook的默认文件夹有关如何处理他们.
As you could see, accessing a default folder that didn't yet exist creates it. See e.g. How to Hide or Delete Outlook's Default Folders on how to deal with them.
这篇关于如何使用GetDefaultFolder获取特定文件夹并删除其创建的不需要的文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!