-
Notifications
You must be signed in to change notification settings - Fork 0
/
Automation_python.py
43 lines (37 loc) · 1.36 KB
/
Automation_python.py
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
import os
from watchdog.events import FileSystemEventHandler
from watchdog.observers import Observer
import time
import json
ext=[]
filepaths = "/Users/pratiksannakki/Desktop/lazy/jj/yo"
class MyHandler(FileSystemEventHandler):
def on_modified(self,event):
for filename in os.listdir(filepaths):
#destpaths= "/Users/pratiksannakki/Documents/hello/Textfile"
ext= os.path.splitext(filename)[-1].lower()
if ext == ".txt":
destpaths= "/Users/pratiksannakki/Desktop/lazy/jj/hello/Textfile"
src=filepaths+"/"+filename
dest=destpaths+"/"+filename
os.rename(src,dest)
elif ext == ".py":
destpaths= "/Users/pratiksannakki/Desktop/lazy/jj/hello/pythonfile"
src=filepaths+"/"+filename
dest=destpaths+"/"+filename
os.rename(src,dest)
else:
destpaths= "/Users/pratiksannakki/Desktop/lazy/jj/hello/unknown"
src=filepaths+"/"+filename
dest=destpaths+"/"+filename
os.rename(src,dest)
eventhandler= MyHandler()
Observer=Observer()
Observer.schedule(eventhandler,filepaths,recursive=True)
Observer.start()
try:
while True:
time.sleep(10)
except KeyboardInterrupt:
Observer.stop()
Observer.join()