-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Expand file tree
/
Copy pathobs.py
More file actions
22 lines (20 loc) · 755 Bytes
/
obs.py
File metadata and controls
22 lines (20 loc) · 755 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
def watcher(path):
# python script to observe changes in a folder
import time
import os
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
from move_to_directory import add_to_dir
class Handler(FileSystemEventHandler):
def on_created(self, event):
if event.event_type == "created":
os.path.basename(event.src_path)
ext = os.path.splitext(event.src_path)[1]
time.sleep(2)
add_to_dir(ext[1:], event.src_path, path)
observer.stop()
observer = Observer()
event_handler = Handler()
observer.schedule(event_handler, path, recursive=True)
observer.start()
observer.join()