Skip to content

Instantly share code, notes, and snippets.

View pagebase's full-sized avatar
🎯
Focusing

Mr. Cat pagebase

🎯
Focusing
View GitHub Profile
@pagebase
pagebase / Sort_Files.py
Created September 1, 2025 18:09
I have written this code to sort specified directory according their file extension such image into image directory, videos into videos directory so on. I have figured out while moving file which is already at destination, the file won't move there and give me error as `file exists`. To handle this error, I have added counter variable, but it gi…
import os
import shutil
try:
# This function handle duplicate files
def handle_duplicate_file(dst, directory_name, file_name, counter):
name, ext=os.path.splitext(file_name) # Split file name extension in list as `["file_name", ".png"]`
new_file_name=f"{file_name}_{counter}{ext}"
return os.path.join(dst, directory_name, new_file_name)