-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheventHandler.py
More file actions
45 lines (39 loc) · 1.67 KB
/
Copy patheventHandler.py
File metadata and controls
45 lines (39 loc) · 1.67 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
import sys
import os
import logging
import time
from watchdog.observers import Observer
from watchdog.events import LoggingEventHandler
from watchdog.events import FileSystemEventHandler
from watchdog.events import PatternMatchingEventHandler
import shutil
class Handle(PatternMatchingEventHandler):
def __init__(self):
PatternMatchingEventHandler.__init__(self, patterns = ['*.xlsx','*.doc', '*.pdf', '*.jpg', '*jpeg', '*.png', '*.gif', '*.exe'],case_sensitive = True, ignore_directories = True)
def on_created(self, event):
if (event.src_path.endswith('.xlsx') or event.src_path.endswith('.doc') or event.src_path.endswith('.pdf')):
print("Document Downloaded. Move to Documents Folder")
shutil.move(event.src_path, "/Users/fenypatel/Documents")
print("moved")
if (event.src_path.endswith('.jpeg') or event.src_path.endswith('.png') or event.src_path.endswith('.jpg') or event.src_path.endswith('.gif')):
print("Image Downloaded. Move to Images Folder")
shutil.move(event.src_path, "/Users/fenypatel/Pictures")
print("moved")
if __name__ == "__main__":
if len(sys.argv) > 1:
path = sys.argv[1]
else:
path = '.'
event_handler = Handle()
observer = Observer()
observer.schedule(event_handler, path, recursive = True)
logging.basicConfig(level=logging.INFO,
format='%(asctime)s - %(message)s',
datefmt='%Y-%m-%d %H:%M:%S')
observer.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join()