Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion File_Organizer/file-organizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
import shutil
import os
import shutil
from watchdog.events import FileSystemEventHandler

class MyHandler(FileSystemEventHandler):
def on_created(self, event):
if not event.is_directory:
Expand All @@ -20,7 +24,13 @@ def on_created(self, event):
other_files = r"C:\Users\Precious pc\Documents\other_files"
# Get the destination directory for the file extension or use the default
destination = destination_mapping.get(file_extension, other_files)
# Move the file to the determined destination
# Validate the file_path and destination
if not os.path.isfile(file_path):
print(f"Error: {file_path} is not a valid file.")
return
if not os.path.isdir(destination):
print(f"Error: {destination} is not a valid directory.")
return
# Check if file already exists in destination & delete it.
if os.path.exists(os.path.join(destination, file_name)):
print(f"File {file_name} already exists in the destination. Deleting it.")
Expand Down