-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfileHandler.py
More file actions
22 lines (17 loc) · 753 Bytes
/
Copy pathfileHandler.py
File metadata and controls
22 lines (17 loc) · 753 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from watchdog.events import FileSystemEventHandler
import os
class FileHandler(FileSystemEventHandler):
tracked_folder = ''
destination_folder = ''
def __init__(self, tracked, destination):
self.tracked_folder = tracked
self.destination_folder = destination
def on_modified(self, event):
for filename in os.listdir(self.tracked_folder):
src = self.tracked_folder + '/' + filename
file_extension = os.path.splitext(filename)[1][1:]
new_destination_folder = f'{self.destination_folder}/{file_extension}'
new_destination = f'{new_destination_folder}/{filename}'
if os.path.exists(new_destination_folder) == False:
os.makedirs(new_destination_folder)
os.rename(src, new_destination)