Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from pathlib import Path
- from inotify.adapters import Inotify
- from inotify.constants import IN_CLOSE_WRITE
- def watch(paths):
- if isinstance(paths, (str, bytes, Path)):
- paths = [paths]
- notify = Inotify()
- for path in paths:
- notify.add_watch(path, mask=IN_CLOSE_WRITE)
- events = notify.event_gen(yield_nones=False)
- for _, event_types, path, file in events:
- target = Path(path, file)
- # print(target, event_types)
- yield target
- notifier = watch('/home/andre')
- for file in notifier:
- print(file.name, 'CONTENT:', file.read_text().strip())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement