-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoutlookmsg.py
More file actions
116 lines (97 loc) · 3.59 KB
/
Copy pathoutlookmsg.py
File metadata and controls
116 lines (97 loc) · 3.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/python
## Import required python modules
import os, glob, sys, datetime
import win32com.client
import win32com
import pandas as pd
import csv
import xlrd
import unicodecsv
# Define current working directory workspace
dir = os.getcwd()
print(dir)
# List all current directory files ending in .msg
filenames = []
for root, dirs, files in os.walk(dir):
for name in files:
if name.endswith(\".msg\"):
filenames.append(name)
print(os.path.abspath(os.path.join(root, name)))
#print(type(filenames)) # This is an iteritable list
print(\"\\n\")
print(\"Total number of Outlook message files: \" + str(len(filenames
# List all current directory files ending in .msg
filenames = []
for root, dirs, files in os.walk(dir):
for name in files:
if name.endswith(\".msg\"):
filenames.append(name)
print(os.path.abspath(os.path.join(root, name)))
#print(type(filenames)) # This is an iteritable list
print(\"\\n\")
print(\"Total number of Outlook message files: \" + str(len(filenames)))"
# Create new folder for attachments files
# Path to be created
path = dir+str(\"\\\\msg_attachments\")
if not os.path.exists(path):
os.makedirs(path)
print(\"Attachments folder created at the following path:\\n\\t\" + path)
# Define current working directory workspace
dir = os.getcwd()
print(dir)
# Utilize win32 api module
outlook = win32com.client.Dispatch(\"Outlook.Application\").GetNamespace(\"MAPI\")
accounts = win32com.client.Dispatch(\"Outlook.Application\").Session.Accounts;
for file in os.listdir(dir):
_, file_extension = os.path.splitext(file)
if file_extension == \".msg\":
print(file)
outlook = win32com.client.Dispatch(\"Outlook.Application\").GetNamespace(\"MAPI\")
msg = outlook.OpenSharedItem(dir + \"\\\\\" + file)
print(\"Message sent on: \" + str(msg.Senton))
att=msg.Attachments
for i in att:
i.SaveAsFile(os.path.join(path, i.Filename))
del outlook, msg
print(\"\\nAttachments extracted from Outlook message files\")"
dir = os.getcwd()
path = dir+str(\"\\\\msg_attachments\")
#os.chdir(path)
#os.chdir(\"..\")
print(\"Changed directories to the following path:\")
print(path)
# List all current directory files ending in .xls
filenames = []
for root, dirs, files in os.walk(dir):
for name in files:
if name.endswith(\".xls\"):
filenames.append(name)
print(os.path.abspath(os.path.join(root, name)))
\n",
#print(type(filenames)) # This is an iteritable list
print(\"\\n\")
print(\"Total number of Termination Report files: \" + str(len(filenames)))"
dir = os.getcwd()
path = dir+str(\"\\\\csv_data_files\")
os.chdir(path)
print(\"Changed directories to the following path:\")
print(path)
csvs = []
for root, dirs, files in os.walk(dir):
for name in files:
if name.endswith(\".csv\"):
csvs.append(name)
print(os.path.abspath(os.path.join(root, name)))
#print(type(filenames)) # This is an iteritable list
print(\"\\n\")
print(\"Total number of Termination Report .csv files: + str(len(csvs)))
os.chdir(\"C:\\\\Users\\\\usrzar\\\\Desktop\\\\local_projects\\\\TDS12.061_terminations\\\\Daily_Term_Emails\")
print(\"Changed directories to:\\n\\t\" + os.getcwd())
mfile = \"Q1_Terminations\"
masterfile = \"master_\" + mfile + \"_\" + datetime.datetime.today().strftime('%m%d%Y') + \".csv\"
print(\"Creating \" + masterfile + \" file within the following path:\")
print(\"\\t\" + path)
for root, dirs, files in os.walk(path):
for name in files:
with open(masterfile, \"w+\") as fout:
pass