标签:try ase obs The keyboard filesyste des 执行 https
安装watchdog包
pip install watchdog
import time from watchdog.observers import Observer from watchdog.events import PatternMatchingEventHandler #各种事件发生时执行的逻辑 def on_created(event): print(f"hey, {event.src_path} has been created!") def on_deleted(event): print(f"what the f**k! Someone deleted {event.src_path}!") def on_modified(event): print(f"hey buddy, {event.src_path} has been modified") def on_moved(event): print(f"ok ok ok, someone moved {event.src_path} to {event.dest_path}") if __name__ == "__main__": #监听类型 patterns = "*" ignore_patterns = "" ignore_directories = False case_sensitive = True my_event_handler = PatternMatchingEventHandler(patterns, ignore_patterns, ignore_directories, case_sensitive) #每种事件执行的代码 my_event_handler.on_created = on_created my_event_handler.on_deleted = on_deleted my_event_handler.on_modified = on_modified my_event_handler.on_moved = on_moved #监听路径 path = r"D:/VSpython/json/" go_recursively = True my_observer = Observer() my_observer.schedule(my_event_handler, path, recursive=go_recursively) #开启监听 my_observer.start() try: while True: time.sleep(1) except KeyboardInterrupt: my_observer.stop() my_observer.join()
标签:try ase obs The keyboard filesyste des 执行 https
原文地址:https://www.cnblogs.com/JinweiChang/p/12133110.html