首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何用msg文件名为.msg(在.msg之前的字符串)重命名outlook (.msg文件)中的附件

如何用msg文件名为.msg(在.msg之前的字符串)重命名outlook (.msg文件)中的附件
EN

Stack Overflow用户
提问于 2022-05-31 16:15:26
回答 1查看 265关注 0票数 0

我有一个文件夹,它有将近12k (.msg)文件,每个文件都有一个csv附件。我设法从每个.msg文件中提取附件的代码。但是,由于依恋和主题是相似的,附件不断超过书面!我尝试用msg.subject重命名,但是msg的主题类似

代码语言:javascript
复制
import win32com.client
import os
inputFolder = r'directory with my msg' ## Change here the input folder
outputFolder = r'directiry for attachments' ## Change here the attachments output folder

for file in os.listdir(inputFolder):
    if file.endswith(".msg"):
        outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
        filePath = inputFolder  + '\\' + file
        msg = outlook.OpenSharedItem(filePath)
        att = msg.Attachments
        for i in att:
            i.SaveAsFile(os.path.join(outputFolder, str(msg.subject + ".csv")))
#Saves the file with the attachment name 
EN

回答 1

Stack Overflow用户

发布于 2022-05-31 16:36:02

您需要找到一种允许唯一标识附件的算法--尝试将附件文件名与电子邮件数据(如ReceivedTime等)结合起来。

在尝试保存附件之前,不要忘记从结果文件名中排除禁止的符号。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72451110

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档