pyinotify for a single file and related error

369 views Asked by At

I know pyinotify can be used to watch for events for all files within a specific directory (recursively). How can I watch for events (say a create event) for a single file only? Basically, I need to have my python code perform some action as soon as it detects for a file with a specific extension (say *.txt) is created.

I have tried looking up for this online but couldn't fine any useful document that guides on how to use pyinotify to explicitly monitor events for a single file as opposed to all files/sub-dirs within a directory.

For e.g. I am trying to watch a 'IN_CREATE' event for a file /tmp/test.txt but when I run my pyinotify script, I get the following error:

[Pyinotify ERROR] add_watch: cannot watch /tmp/test.txt (WD=-1)

One of the articles online indicated this could be due to limit on max_user_watches, so i tried to increase that limit (fs.inotify.max_user_watches) but no luck.

Any thoughts on why I would be getting this error message or anyone already knows details about this error?

Thanks.

1

There are 1 answers

0
ebal On

The /tmp/test.txt exist already ?

If not then you need to monitor recursive the /tmp and ExcludeFilter the output