用Outlook.OpenSharedItem打开带有空格的文件时出现错误 [英] Opening files with spaces with outlook.OpenSharedItem is giving error
问题描述
我得到了以下代码:
import win32com.client
import os
directory = "C:/Users/mypath/"
for filename in os.listdir(directory):
_, file_extension = os.path.splitext(filename)
if file_extension == ".msg":
print(filename)
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
msg = outlook.OpenSharedItem(directory + filename)
att=msg.Attachments
for i in att:
i.SaveAsFile(os.path.join(directory, i.FileName))
del outlook, msg
此代码提取附加到.msg的文件,当我运行它时,得到以下输出:
This code extracts the files attached to a .msg and when I run it, I got the following output:
ATP-3770289.msg ATP-5126209.msg ATP-5126317.msg ATT -1937501.msgcom_error:(-2147352567,发生了异常.",(4096,"Microsoft Outlook",我们无法打开'C://Users/omar.lopez.rubio/Desktop/admisiones/ATT%20-1937501.msg'.该文件可能已经打开,或者您没有打开它的权限.\ n \ n要检查权限,请右键单击该文件夹,然后单击属性".,无,0,-2147287038),没有)
ATP-3770289.msg ATP-5126209.msg ATP-5126317.msg ATT -1937501.msg com_error: (-2147352567, 'Exception occurred.', (4096, 'Microsoft Outlook', "We can't open 'C://Users/omar.lopez.rubio/Desktop/admisiones/ATT%20-1937501.msg'. It's possible the file is already open, or you don't have permission to open it.\n\nTo check your permissions, right-click the file folder, then click Properties.", None, 0, -2147287038), None)
明显是由于
ATT -1937501.msg
ATT -1937501.msg
有一个空格.我正在Windows的Spyder上运行此程序.任何线索如何解决这个问题?谢谢.
has a space. I'm running this on Spyder in windows. Any clues how to solve this? Thanks.
推荐答案
在运行python程序时关闭您的界面
close your outlook while running the python program
这篇关于用Outlook.OpenSharedItem打开带有空格的文件时出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!