我有一个文件夹,它有将近12k (.msg)文件,每个文件都有一个csv附件。我设法从每个.msg文件中提取附件的代码。但是,由于依恋和主题是相似的,附件不断超过书面!我尝试用msg.subject重命名,但是msg的主题类似
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 发布于 2022-05-31 16:36:02
您需要找到一种允许唯一标识附件的算法--尝试将附件文件名与电子邮件数据(如ReceivedTime等)结合起来。
在尝试保存附件之前,不要忘记从结果文件名中排除禁止的符号。
https://stackoverflow.com/questions/72451110
复制相似问题