Organize 1000+ Messy Files in 2 Seconds! (Python Automation)

Опубликовано: 04 Июль 2026
на канале: Ali Ahmed's AI Lab
3
0

🚀 Clean Your Chaotic Downloads Folder in 2 Minutes! – Urdu/Hindi AI Tutorial with English Subs!

Stop spending hours manually dragging and dropping files into folders! Today, we are solving the ultimate PC headache—a messy Downloads folder filled with random images, videos, and PDFs. Watch as we write a simple but powerful Python script that instantly reads file extensions and sorts thousands of files into perfectly organized folders. Zero manual sorting required!

⏰ Timestamps:
0:00 Intro & The Messy Downloads Problem
0:10 Opening VS Code / PyCharm
0:46 The Python Organizer Script Explained
1:00 Running the Script (Live Demo)
1:12 The Magic: 2-Second Folder Organization!
1:58 Outro: Join the 1 Million Subs Mission

🔗 Resources:

Python Official Website: https://www.python.org/downloads/

Python Script for File Organizer (organizer.py):
import shutil
from pathlib import Path


def organize_downloads(folder_path):
"""
Organizes files in the specified folder based on their extensions.
Production-grade script with exception handling and duplicate file protection.
"""

Dictionary mapping file extensions to their respective Folder names
EXTENSION_MAP = {
'.mp4': 'Videos',
'.ogg': 'WhatsApp Audio',
'.mp3': 'Audio',
'.wav': 'WAV Files',
'.png': 'Pictures',
'.jpeg': 'Pictures',
'.jpg': 'Pictures',
-- NEW SPECIFIC DOCUMENT FOLDERS --
'.pdf': 'PDF Files',
'.doc': 'Word Documents',
'.docx': 'Word Documents',
'.xls': 'Excel Sheets',
'.xlsx': 'Excel Sheets',
'.csv': 'Excel Sheets',
'.ppt': 'Presentations',
'.pptx': 'Presentations'
}

target_dir = Path(folder_path)

Check if the provided path exists and is indeed a directory
if not target_dir.exists() or not target_dir.is_dir():
print(f"Error: The directory '{folder_path}' does not exist or is invalid.")
return

print(f"Starting to organize files in: {folder_path} ...\n")

Iterate through all items in the target directory
for file_path in target_dir.iterdir():

Skip directories (we only want to move files)
if file_path.is_dir():
continue

try:
Get the file extension in lowercase (e.g., '.mp4')
file_ext = file_path.suffix.lower()

Determine the destination folder based on the extension map
folder_name = EXTENSION_MAP.get(file_ext, 'Others')

Create the destination folder path
dest_folder = target_dir / folder_name

Create the folder if it doesn't already exist (SAFE FOR REPEAT RUNS)
dest_folder.mkdir(parents=True, exist_ok=True)

-- Duplicate File Handler --
dest_file_path = dest_folder / file_path.name
counter = 1
If a file with the exact same name exists, add _1, _2, etc. to the filename
while dest_file_path.exists():
new_name = f"{file_path.stem}_{counter}{file_path.suffix}"
dest_file_path = dest_folder / new_name
counter += 1
-----------------------------------

Move the file to its safely generated new path
shutil.move(str(file_path), str(dest_file_path))
print(f"Success: Moved '{file_path.name}' - '{folder_name}/{dest_file_path.name}'")

except PermissionError:
print(
f"Permission Denied: Could not move '{file_path.name}'. The file might be open or in use by another program.")
except FileNotFoundError:
print(f"File Not Found: '{file_path.name}' might have been deleted or moved already.")
except Exception as e:
print(f"An unexpected error occurred with '{file_path.name}': {str(e)}")

print("\nProcess Completed: All files have been organized successfully!")


if _name_ == "__main__":
Updated with your exact Downloads folder path
DOWNLOADS_FOLDER_PATH = r"C:\Users\Wajiz.pk\Downloads"

organize_downloads(DOWNLOADS_FOLDER_PATH)

👍 If this Python automation saved you hours of work, please Like and Share it with your friends!
🔔 Subscribe to Ali Ahmed's AI Lab and drop a comment below on what you want me to automate with Python next. Join the journey to 1 Million+ subscribers!

#PythonAutomation #FileOrganizer #PythonProjects #AutomateWithPython #UrduAI

🌐 GitHub: https://github.com/ali112919821
💼 LinkedIn:   / ali112919821  
📧 For Business: [email protected]