Advanced Python Project: Build Your Own Smart File Organizer!
š Level Up Your Python Skills! š Today's project: Smart File Organizer š Tired of messy folders? Build a Python automation tool that automatically sorts files into different folders based on file extensions. š” What you'll learn: File handling with os File management with shutil Functions and dictionaries Loops and conditional statements Automation using Python š„ Coding Challenge: Can you upgrade this project to automatically detect duplicate files and generate an organization report? Keep learning. Keep building. Keep coding! š» #Python #AdvancedPython #PythonProjects #Automation #CodingCommunity #LearnProgramming
import os
import shutil
def organize_files(folder_path):
file_types = {
"Images": [".jpg", ".jpeg", ".png", ".gif"],
"Documents": [".pdf", ".docx", ".txt", ".xlsx"],
"Videos": [".mp4", ".mkv", ".avi"],
"Music": [".mp3", ".wav"],
"Archives": [".zip", ".rar"]
}
for filename in os.listdir(folder_path):
file_path = os.path.join(folder_path, filename)
if os.path.isfile(file_path):
extension = os.path.splitext(filename)[1].lower()
for folder, extensions in file_types.items():
if extension in extensions:
target_folder = os.path.join(folder_path, folder)
os.makedirs(target_folder, exist_ok=True)
shutil.move(
file_path,
os.path.join(target_folder, filename)
)
print(f"Moved: {filename} ā {folder}")
break
print("\nā
File organization completed!")
path = input("Enter folder path: ")
organize_files(path)