0% found this document useful (0 votes)
1 views1 page

11 Python File Organizer

The document provides a Python script that organizes files in a specified directory into categorized folders based on their extensions. It defines an extension map for Images, Code, Documents, and Archives, and moves files accordingly. Users can run the script in any cluttered directory to streamline file organization.

Uploaded by

mohabehab05
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views1 page

11 Python File Organizer

The document provides a Python script that organizes files in a specified directory into categorized folders based on their extensions. It defines an extension map for Images, Code, Documents, and Archives, and moves files accordingly. Users can run the script in any cluttered directory to streamline file organization.

Uploaded by

mohabehab05
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Python File Organizer Script

Automation & Utility Scripting

Python Script
import os
import shutil

EXTENSION_MAP = {
"Images": [".png", ".jpg", ".jpeg", ".svg", ".gif"],
"Code": [".gd", ".py", ".html", ".css", ".js", ".json"],
"Documents": [".pdf", ".docx", ".txt", ".md", ".csv"],
"Archives": [".zip", ".tar", ".gz", ".7z"]
}

def organize_folder(target_dir="."):
for filename in [Link](target_dir):
filepath = [Link](target_dir, filename)
if [Link](filepath):
ext = [Link](filename)[1].lower()
for folder_name, extensions in EXTENSION_MAP.items():
if ext in extensions:
dest_folder = [Link](target_dir, folder_name)
[Link](dest_folder, exist_ok=True)
[Link](filepath, [Link](dest_folder, filename))
print(f"Moved {filename} -> {folder_name}/")
break

if __name__ == "__main__":
organize_folder()

Usage Notes
Run this script in any messy directory (like Downloads) to automatically group files into Images, Code,
Documents, and Archives folders.

You might also like