Hello everyone,
I would like to script a function wich is looking in a particular directory for files, if there are new files, it should send out an notification email.
I already prepared a script which is looking for new files in a directory, it write the notification about a new file into the console. But now I would like to notified via email, as soon as there has a new file arrived. Could someone help?
Thank you in advance!
import os, time
def run():
path_to_watch = "//D$:/testfolder/"
print "watching: " + path_to_watch
before = dict ([(f, None) for f in os.listdir (path_to_watch)])
while 1:
after = dict ([(f, None) for f in os.listdir (path_to_watch)])
added = [f for f in after if not f in before]
removed = [f for f in before if not f in after]
if added: print "Added: ", ", ".join (added)
if removed: print "Removed: ", ", ".join (removed)
before = after
time.sleep (10)
if __name__ == "__main__":
print run()