views:

56

answers:

2

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()
A: 

It's very simple if you have an SMTP mail server set up (i'm assuming you have a mail system!). Will take you about 10 lines of code in total. Here is a python example.

If you have any problems, we will need more information to help further. For example, what mail system you are using e.t.c.

sillyMunky