I’m writing a program in Python that stores information for every file on the system. When it’s installed, it will walk over every file, but afterwards I want to update it whenever a new file is created, or when a file is moved. For example, In the Dropbox service, whenever I copy a file into my Dropbox dir, it immediately notices and uploads it to their server.
Is there a way to do this in Python without polling? I’m thinking about some sort of an event listener that is triggered when a file is created.
Try one of:
I think first of them is simpler to use. Example of use (from its site):
watcher is module that wraps system API, and is described on MSDN:
http://msdn.microsoft.com/en-us/library/aa365465(v=vs.85).aspx
So, flag
watcher.FILE_NOTIFY_CHANGE_FILE_NAMEsays that you will be notified about: