使用watchdog模块 文件夹打开时 会有文件被修改的提示
[Python] 纯文本查看 复制代码 from watchdog.observers import Observer
from watchdog.events import *
import time
a = r"C:\Users"
class MyHandler(FileSystemEventHandler):
def on_modified(self, event):
print("文件被修改了 %s"%event.src_path)
def on_created(self, event):
print("文件被创建了 %s" % event.src_path)
if __name__ == "__main__":
path = a
event_handler = MyHandler()
observer = Observer()
observer.schedule(event_handler, path, recursive=True)
observer.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join()
|