Skip to content

Instantly share code, notes, and snippets.

@heygema
Created October 19, 2020 12:11
Show Gist options
  • Save heygema/9621ef9833a0749f5ff453ddcd69b103 to your computer and use it in GitHub Desktop.
Save heygema/9621ef9833a0749f5ff453ddcd69b103 to your computer and use it in GitHub Desktop.
Python watchdog observer
#!/usr/local/bin/python3
from watchdog.observers import Observer
import time
from watchdog.events import FileSystemEventHandler
import os
import json
class MyHandler(FileSystemEventHandler):
def on_modified(self, event):
print(f"modified {event}")
folder_to_track = '/Users/Me/myFolder'
event_handler = MyHandler()
observer = Observer()
observer.schedule(event_handler, folder_to_track, recursive=True)
observer.start()
try:
while True:
time.sleep(10)
except KeyboardInterrupt:
observer.stop()
observer.join()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment