pyinotify icon indicating copy to clipboard operation
pyinotify copied to clipboard

Files created in subdirectories not watched

Open p1nox opened this issue 8 years ago • 1 comments

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

p1nox avatar Jul 20 '16 14:07 p1nox

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

slytomcat avatar Oct 15 '16 07:10 slytomcat