From 2a9fee8175ccef3f4ea414d1ddbd70526ee8b633 Mon Sep 17 00:00:00 2001 From: Bestbrainof24 <187941507+Bestbrainof24@users.noreply.github.com> Date: Sat, 5 Sep 2026 16:48:49 +0300 Subject: [PATCH 1/7] refactor: replace os.path with Pathlib --- File_Organizer/file-organizer.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/File_Organizer/file-organizer.py b/File_Organizer/file-organizer.py index f11dec7..9cc7015 100644 --- a/File_Organizer/file-organizer.py +++ b/File_Organizer/file-organizer.py @@ -1,13 +1,23 @@ -import os +from pathlib import Path +import shutil + from watchdog.observers import Observer from watchdog.events import FileSystemEventHandler -import shutil + +FILE_TYPES: dict[str, list[str]] = { + "images": [".jpg", ".jpeg", ".png", ".gif", ".webp"], + "videos": [".mp4", ".mkv", ".avi", ".mov"], + "audio": [".mp3", ".wav", ".flac", ".m4a"], + "documents": [".pdf", ".docx", ".txt"], + "archives": [".zip", ".rar", ".7z"], +} + class MyHandler(FileSystemEventHandler): def on_created(self, event): if not event.is_directory: - file_path = event.src_path - file_name = os.path.basename(file_path) - file_extension = os.path.splitext(file_name)[1].lower() + file_path = Path(event.src_path) + file_name = file_path.name + file_extension = file_path.suffix.lower() # A dictionary takes file extensions & folder to move each formats to. destination_mapping = { # Key = Format/extension to handle : Value = Folder to move file format. @@ -22,11 +32,12 @@ def on_created(self, event): destination = destination_mapping.get(file_extension, other_files) # Move the file to the determined destination # Check if file already exists in destination & delete it. - if os.path.exists(os.path.join(destination, file_name)): + if Path.exists(Path(destination).joinpath(file_name)): print(f"File {file_name} already exists in the destination. Deleting it.") - os.remove(os.path.join(destination, file_name)) + Path.unlink(Path(destination).joinpath(file_name)) # Move the file to the determined destination shutil.move(file_path, destination) + if __name__ == "__main__": folder_to_watch = r"C:\Users\Precious pc\Documents\monitor" # Replace with the directory you want to monitor event_handler = MyHandler() From bcad703a303475e4e30e03c32d001aff8670cc90 Mon Sep 17 00:00:00 2001 From: Bestbrainof24 <187941507+Bestbrainof24@users.noreply.github.com> Date: Sat, 5 Sep 2026 17:14:26 +0300 Subject: [PATCH 2/7] refactor: use categories and portable paths --- File_Organizer/file-organizer.py | 36 +++++++++++++++++++------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/File_Organizer/file-organizer.py b/File_Organizer/file-organizer.py index 9cc7015..e554621 100644 --- a/File_Organizer/file-organizer.py +++ b/File_Organizer/file-organizer.py @@ -4,6 +4,7 @@ from watchdog.observers import Observer from watchdog.events import FileSystemEventHandler +CURRENT_WORKING_DIR = Path.cwd() FILE_TYPES: dict[str, list[str]] = { "images": [".jpg", ".jpeg", ".png", ".gif", ".webp"], "videos": [".mp4", ".mkv", ".avi", ".mov"], @@ -16,30 +17,37 @@ class MyHandler(FileSystemEventHandler): def on_created(self, event): if not event.is_directory: file_path = Path(event.src_path) - file_name = file_path.name + file_name = file_path.name file_extension = file_path.suffix.lower() - # A dictionary takes file extensions & folder to move each formats to. + category = "" + + for category_name, extensions in FILE_TYPES.items(): + if file_extension in extensions: + category = category_name + break + else: + category = "others" + destination_mapping = { - # Key = Format/extension to handle : Value = Folder to move file format. - ".zip": r"C:\Users\Precious pc\Documents\Zip files", - ".png": r"C:\Users\Precious pc\Documents\png_files", - ".psd": r"C:\Users\Precious pc\Documents\psd_destination", - ".pdf": r"C:\Users\Precious pc\Documents\pdf_files", + "images": CURRENT_WORKING_DIR / "Images", + "videos": CURRENT_WORKING_DIR / "Videos", + "audio": CURRENT_WORKING_DIR / "Audio Files", + "documents": CURRENT_WORKING_DIR / "Documents", + "archives": CURRENT_WORKING_DIR / "Archives", + "others": CURRENT_WORKING_DIR / "Others" } - # Default destination for unknown extensions - 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) + + destination = destination_mapping[category] # Move the file to the determined destination # Check if file already exists in destination & delete it. - if Path.exists(Path(destination).joinpath(file_name)): + if Path(destination).joinpath(file_name).exists(): print(f"File {file_name} already exists in the destination. Deleting it.") - Path.unlink(Path(destination).joinpath(file_name)) + Path(destination).joinpath(file_name).unlink() # Move the file to the determined destination shutil.move(file_path, destination) if __name__ == "__main__": - folder_to_watch = r"C:\Users\Precious pc\Documents\monitor" # Replace with the directory you want to monitor + folder_to_watch = CURRENT_WORKING_DIR / "monitor" event_handler = MyHandler() observer = Observer() observer.schedule(event_handler, path=folder_to_watch, recursive=False) # Set recursive to True if you want to monitor subdirectories From e59c17eda4ca206595cd04b0b386021d6cec3573 Mon Sep 17 00:00:00 2001 From: Bestbrainof24 <187941507+Bestbrainof24@users.noreply.github.com> Date: Sat, 5 Sep 2026 18:11:49 +0300 Subject: [PATCH 3/7] fix: handle duplicate filenames safely --- File_Organizer/file-organizer.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/File_Organizer/file-organizer.py b/File_Organizer/file-organizer.py index e554621..4e2fba5 100644 --- a/File_Organizer/file-organizer.py +++ b/File_Organizer/file-organizer.py @@ -36,15 +36,21 @@ def on_created(self, event): "archives": CURRENT_WORKING_DIR / "Archives", "others": CURRENT_WORKING_DIR / "Others" } - destination = destination_mapping[category] - # Move the file to the determined destination - # Check if file already exists in destination & delete it. - if Path(destination).joinpath(file_name).exists(): - print(f"File {file_name} already exists in the destination. Deleting it.") - Path(destination).joinpath(file_name).unlink() - # Move the file to the determined destination - shutil.move(file_path, destination) + + if destination.joinpath(file_name).exists(): + print(f"File {file_name} already exists in the destination. Renaming it") + count = 1 + while True: + if destination.joinpath(f"{file_path.stem}_{count}{file_extension}").exists(): + count += 1 + else: + destination_path = destination / f"{file_path.stem}_{count}{file_extension}" + break + else: + destination_path = destination / file_name + + shutil.move(file_path, destination_path) if __name__ == "__main__": folder_to_watch = CURRENT_WORKING_DIR / "monitor" From 0501e11b32710aff3ce94efe677752a3e57779bc Mon Sep 17 00:00:00 2001 From: Bestbrainof24 <187941507+Bestbrainof24@users.noreply.github.com> Date: Sat, 5 Sep 2026 21:26:38 +0300 Subject: [PATCH 4/7] fix: prevent busy loop from consuming CPU by using time.sleep() --- File_Organizer/file-organizer.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/File_Organizer/file-organizer.py b/File_Organizer/file-organizer.py index 4e2fba5..a22768f 100644 --- a/File_Organizer/file-organizer.py +++ b/File_Organizer/file-organizer.py @@ -1,5 +1,6 @@ from pathlib import Path import shutil +import time from watchdog.observers import Observer from watchdog.events import FileSystemEventHandler @@ -60,7 +61,7 @@ def on_created(self, event): observer.start() try: while True: - pass + time.sleep(60) except KeyboardInterrupt: observer.stop() observer.join() From 8c9f61f9b2d3d277a3eb7252ae6edfd8fb8f241b Mon Sep 17 00:00:00 2001 From: Bestbrainof24 <187941507+Bestbrainof24@users.noreply.github.com> Date: Sat, 5 Sep 2026 21:31:49 +0300 Subject: [PATCH 5/7] refactor: add type annotations --- File_Organizer/file-organizer.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/File_Organizer/file-organizer.py b/File_Organizer/file-organizer.py index a22768f..a403daa 100644 --- a/File_Organizer/file-organizer.py +++ b/File_Organizer/file-organizer.py @@ -3,9 +3,9 @@ import time from watchdog.observers import Observer -from watchdog.events import FileSystemEventHandler +from watchdog.events import FileSystemEvent, FileSystemEventHandler -CURRENT_WORKING_DIR = Path.cwd() +CURRENT_WORKING_DIR: Path = Path.cwd() FILE_TYPES: dict[str, list[str]] = { "images": [".jpg", ".jpeg", ".png", ".gif", ".webp"], "videos": [".mp4", ".mkv", ".avi", ".mov"], @@ -15,12 +15,12 @@ } class MyHandler(FileSystemEventHandler): - def on_created(self, event): + def on_created(self, event: FileSystemEvent) -> None: if not event.is_directory: - file_path = Path(event.src_path) - file_name = file_path.name - file_extension = file_path.suffix.lower() - category = "" + file_path: Path = Path(event.src_path) + file_name: str = file_path.name + file_extension: str = file_path.suffix.lower() + category: str = "" for category_name, extensions in FILE_TYPES.items(): if file_extension in extensions: @@ -29,7 +29,7 @@ def on_created(self, event): else: category = "others" - destination_mapping = { + destination_mapping: dict[str, Path] = { "images": CURRENT_WORKING_DIR / "Images", "videos": CURRENT_WORKING_DIR / "Videos", "audio": CURRENT_WORKING_DIR / "Audio Files", @@ -37,7 +37,7 @@ def on_created(self, event): "archives": CURRENT_WORKING_DIR / "Archives", "others": CURRENT_WORKING_DIR / "Others" } - destination = destination_mapping[category] + destination: Path = destination_mapping[category] if destination.joinpath(file_name).exists(): print(f"File {file_name} already exists in the destination. Renaming it") @@ -54,7 +54,7 @@ def on_created(self, event): shutil.move(file_path, destination_path) if __name__ == "__main__": - folder_to_watch = CURRENT_WORKING_DIR / "monitor" + folder_to_watch: Path = CURRENT_WORKING_DIR / "monitor" event_handler = MyHandler() observer = Observer() observer.schedule(event_handler, path=folder_to_watch, recursive=False) # Set recursive to True if you want to monitor subdirectories From ab2a72b96f307e61de5602f6358211728fad602d Mon Sep 17 00:00:00 2001 From: Bestbrainof24 <187941507+Bestbrainof24@users.noreply.github.com> Date: Sat, 5 Sep 2026 21:41:00 +0300 Subject: [PATCH 6/7] refactor: improve handler structure and configuration --- File_Organizer/file-organizer.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/File_Organizer/file-organizer.py b/File_Organizer/file-organizer.py index a403daa..233a227 100644 --- a/File_Organizer/file-organizer.py +++ b/File_Organizer/file-organizer.py @@ -13,8 +13,16 @@ "documents": [".pdf", ".docx", ".txt"], "archives": [".zip", ".rar", ".7z"], } +DESTINATION_MAPPING: dict[str, Path] = { + "images": CURRENT_WORKING_DIR / "Images", + "videos": CURRENT_WORKING_DIR / "Videos", + "audio": CURRENT_WORKING_DIR / "Audio Files", + "documents": CURRENT_WORKING_DIR / "Documents", + "archives": CURRENT_WORKING_DIR / "Archives", + "others": CURRENT_WORKING_DIR / "Others" +} -class MyHandler(FileSystemEventHandler): +class FileEventHandler(FileSystemEventHandler): def on_created(self, event: FileSystemEvent) -> None: if not event.is_directory: file_path: Path = Path(event.src_path) @@ -29,15 +37,7 @@ def on_created(self, event: FileSystemEvent) -> None: else: category = "others" - destination_mapping: dict[str, Path] = { - "images": CURRENT_WORKING_DIR / "Images", - "videos": CURRENT_WORKING_DIR / "Videos", - "audio": CURRENT_WORKING_DIR / "Audio Files", - "documents": CURRENT_WORKING_DIR / "Documents", - "archives": CURRENT_WORKING_DIR / "Archives", - "others": CURRENT_WORKING_DIR / "Others" - } - destination: Path = destination_mapping[category] + destination: Path = DESTINATION_MAPPING[category] if destination.joinpath(file_name).exists(): print(f"File {file_name} already exists in the destination. Renaming it") @@ -55,7 +55,7 @@ def on_created(self, event: FileSystemEvent) -> None: if __name__ == "__main__": folder_to_watch: Path = CURRENT_WORKING_DIR / "monitor" - event_handler = MyHandler() + event_handler = FileEventHandler() observer = Observer() observer.schedule(event_handler, path=folder_to_watch, recursive=False) # Set recursive to True if you want to monitor subdirectories observer.start() From 7a3072a93692fd7cda421c58aeab6efdb6c5ca66 Mon Sep 17 00:00:00 2001 From: Bestbrainof24 <187941507+Bestbrainof24@users.noreply.github.com> Date: Sat, 5 Sep 2026 21:51:37 +0300 Subject: [PATCH 7/7] fix: update scikit-learn to patched version in requirments.txt --- Binary-Gene-Classifier-Model/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Binary-Gene-Classifier-Model/requirements.txt b/Binary-Gene-Classifier-Model/requirements.txt index 3266877..4936433 100644 --- a/Binary-Gene-Classifier-Model/requirements.txt +++ b/Binary-Gene-Classifier-Model/requirements.txt @@ -1,5 +1,5 @@ numpy==1.25.0 pandas==2.0.1 scipy==1.11.0 -scikit-learn==1.3.0 +scikit-learn>=1.5.0 datasets==2.16.0 \ No newline at end of file