Nov-22-2022, 11:02 PM
I need to copy and paste a file with certain extensions from one location to another and receive notify by Mail from outlook if file it doesn't already exist in the destination folder
if already file exists in the destination folder : Skip and no send any notification
NB* : I don't want to be copying everything every single time, just those files that don't exist in the destination folder.
My code
if already file exists in the destination folder : Skip and no send any notificationNB* : I don't want to be copying everything every single time, just those files that don't exist in the destination folder.
My code
import glob
import os
import shutil
import os
import win32com.client as win32
# Outlook application instance
olApp = win32.Dispatch('Outlook.Application')
olNS = olApp.GetNameSpace('MAPI')
# path
src = '/Users/Administrator/Desktop/A'
dst = '/Users/Administrator/Desktop/B'
# check if the file exists in dst with extensions
file = os.path.join(os.path.join(src, "*.txt"))
if os.path.exists(dst):
for file in glob.iglob(os.path.join(src, "*.txt")):
if os.path.isfile(file):
shutil.copy2(file, dst)
mailItem = olApp.CreateItem(0)
mailItem.Subject = 'Check file'
mailItem.BodyFormat = 1
mailItem.Body = "File is Successful Copy"
mailItem.To = '<[email protected]>'
#mailItem.Attachments.Add()
mailItem.send
else:
print(" Skipped: already file exists ")
