Created
October 19, 2020 12:11
-
-
Save heygema/9621ef9833a0749f5ff453ddcd69b103 to your computer and use it in GitHub Desktop.
Python watchdog observer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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