Is it possible to monitor every file creation on a Windows drive?
Question: 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.


Answer: Try one of:

  * <http://pypi.python.org/pypi/watcher>
  * <http://pypi.python.org/pypi/watchdog>

I think first of them is simpler to use. Example of use (from its site):

    
    
    import watcher
    w = watcher.Watcher(dir, callback)
    w.flags = watcher.FILE_NOTIFY_CHANGE_FILE_NAME
    w.start()
    

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_NAME` says that you will be notified
about:

> Any file name change in the watched directory or subtree causes a change
> notification wait operation to return. Changes include renaming, creating,
> or deleting a file.

