pyinotify
pyinotify copied to clipboard
Files created in subdirectories not watched
Using this code one can (theoretically) watch for new files added to the target directory and subdirectories. When a files is created in this directory an event is fired, also when a directory is created inside target directory an event is fired, but then when a file is added/created inside this subdirectory no event is fired.
import os
import pyinotify
class DirHandler(pyinotify.ProcessEvent):
def process_IN_CREATE(self, event):
print '###', event, event.dir
def main():
wm = pyinotify.WatchManager()
notifier = pyinotify.ThreadedNotifier(wm, DirHandler())
wm.add_watch('/directory/to/watch', pyinotify.IN_CREATE, rec=True)
notifier.loop()
main()
Use auto_add=True in add_watch wm.add_watch('/directory/to/watch', pyinotify.IN_CREATE, rec=True, auto_add=True)
https://github.com/seb-m/pyinotify/wiki/Frequently-Asked-Questions