-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWatchDogModule.py
More file actions
46 lines (38 loc) · 1.63 KB
/
WatchDogModule.py
File metadata and controls
46 lines (38 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import time
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
class MyHandler(FileSystemEventHandler):
def on_created(self, event):
now = time.localtime()
nowtime = time.strftime("%Y/%m/%d %H:%M:%S", now)
print(nowtime, " " * (20 - len(nowtime)), f" {event.src_path} is created")
def on_opened(self, event):
now = time.localtime()
nowtime = time.strftime("%Y/%m/%d %H:%M:%S", now)
print(nowtime, " " * (20 - len(nowtime)), f" {event.src_path} is opened")
def on_modified(self, event):
now = time.localtime()
nowtime = time.strftime("%Y/%m/%d %H:%M:%S", now)
print(nowtime + " " * (20 - len(nowtime)), f"{event.src_path} is modified")
def on_closed(self, event):
now = time.localtime()
nowtime = time.strftime("%Y/%m/%d %H:%M:%S", now)
print(nowtime + " " * (20 - len(nowtime)), f"{event.src_path} is closed")
def on_deleted(self, event):
now = time.localtime()
nowtime = time.strftime("%Y/%m/%d %H:%M:%S", now)
print(nowtime + " " * (20 - len(nowtime)), f" {event.src_path} is deleted")
def on_moved(self, event):
now = time.localtime()
nowtime = time.strftime("%Y/%m/%d %H:%M:%S", now)
print(nowtime + " " * (20 - len(nowtime)), f" {event.src_path} is moved")
observer = Observer()
event_handler = MyHandler()
observer.schedule(event_handler, path="C:/Users/batug/OneDrive/Masaüstü/WatchdogFile", recursive=True)
observer.start()
try:
while True:
time.sleep(300)
except KeyboardInterrupt:
observer.stop()
observer.join()