Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 120 additions & 0 deletions Auto_File_Organizer_#1747/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@

# Automatic Downloads Organizer

> A Python utility that automatically organizes your **Downloads** folder by moving files into categorized subfolders based on their type.

---

## Features

* Automatically detects and categorizes files by extension
* Creates folders for each category (e.g., *Images*, *Documents*, *Videos*, *Music*, etc.)
* Moves files into their respective folders
* Works across **Windows**, **macOS**, and **Linux**
* No external libraries required — uses Python’s built-in modules

---

## 🧩 Categories and File Types

| Category | File Extensions |
| ---------------- | ------------------------------------------------------------------------- |
| **Images** | `.jpg`, `.jpeg`, `.png`, `.gif`, `.bmp`, `.tiff`, `.svg` |
| **Documents** | `.pdf`, `.doc`, `.docx`, `.txt`, `.ppt`, `.pptx`, `.xls`, `.xlsx`, `.csv` |
| **Videos** | `.mp4`, `.mkv`, `.avi`, `.mov`, `.wmv`, `.flv` |
| **Music** | `.mp3`, `.wav`, `.aac`, `.flac`, `.ogg`, `.m4a` |
| **Archives** | `.zip`, `.rar`, `.tar`, `.gz`, `.7z` |
| **Applications** | `.exe`, `.msi`, `.dmg`, `.pkg`, `.app` |
| **Others** | Any unsupported or unknown file type |

---

## Example

### Before:

```
photo.jpg
report.pdf
song.mp3
video.mp4
installer.exe
randomfile.xyz
```

### After running the script:

```
Downloads/
├── Images/
│ └── photo.jpg
├── Documents/
│ └── report.pdf
├── Music/
│ └── song.mp3
├── Videos/
│ └── video.mp4
├── Applications/
│ └── installer.exe
└── Others/
└── randomfile.xyz
```

---

## How It Works

1. Scans your **Downloads** folder for all files.
2. Determines each file’s type based on its extension.
3. Automatically creates category folders (if missing).
4. Moves files into their appropriate folders.
5. Displays a summary of all moved files in the terminal.

---

## Usage

### 1. Clone or Download the Script

Download or copy `organize_downloads.py` to your computer.

### 2. Run the Script

Open a terminal or command prompt and run:

```bash
python organize_downloads.py
```

### 3. Output Example

```
Automatic Downloads Organizer
Target folder: /Users/Downloads

Moved: photo.jpg → Images/
Moved: resume.pdf → Documents/
Moved: song.mp3 → Music/
Moved: installer.exe → Applications/

Downloads folder organized successfully!
```

---

## Requirements

* **Python 3.6+**
* Works on **Windows**, **macOS**, and **Linux**
* Uses built-in modules: `os`, `shutil`, and `pathlib` — no installation needed

---

## Notes

* Files are **moved**, not copied — back up if necessary.
* Only organizes files directly in the **Downloads** folder (not subfolders).
* Skips already-organized files inside existing category folders.
* Make sure the script has permission to modify the Downloads folder.

---
97 changes: 97 additions & 0 deletions Auto_File_Organizer_#1747/auto_organize_downloads.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
"""
This script automatically organizes files in the user's Downloads folder
by moving them into categorized subfolders based on file type.

Example:
A file named 'photo.jpg' will be moved to the 'Images' folder.
A file named 'report.pdf' will be moved to the 'Documents' folder.

Supported categories:
- Images
- Documents
- Videos
- Music
- Archives
- Applications
- Others
"""

import os
import shutil
from pathlib import Path

def organize_downloads(downloads_path: str) -> None:
"""
Organize files in the specified Downloads folder by file type.

Args:
downloads_path (str): The path to the user's Downloads folder.

Returns:
None
"""
# Define file categories and their associated extensions
categories = {
"Images": [".jpg", ".jpeg", ".png", ".gif", ".bmp", ".tiff", ".svg"],
"Documents": [".pdf", ".doc", ".docx", ".txt", ".ppt", ".pptx", ".xls", ".xlsx", ".csv"],
"Videos": [".mp4", ".mkv", ".avi", ".mov", ".wmv", ".flv"],
"Music": [".mp3", ".wav", ".aac", ".flac", ".ogg", ".m4a"],
"Archives": [".zip", ".rar", ".tar", ".gz", ".7z"],
"Applications": [".exe", ".msi", ".dmg", ".pkg", ".app"],
}

# Convert path string to Path object for easier handling
downloads_dir = Path(downloads_path)

# Validate that the provided path is a directory
if not downloads_dir.is_dir():
print(f"Error: '{downloads_path}' is not a valid directory.")
return

# List all files in the Downloads folder (ignore subfolders)
files = [f for f in downloads_dir.iterdir() if f.is_file()]

if not files:
print("No files found in the Downloads folder.")
return

# Iterate over files and move them into categorized folders
for file_path in files:
file_extension = file_path.suffix.lower() # e.g., '.jpg'
destination_folder = None

# Determine which category the file belongs to
for category, extensions in categories.items():
if file_extension in extensions:
destination_folder = downloads_dir / category
break

# If no matching category, move to "Others"
if not destination_folder:
destination_folder = downloads_dir / "Others"

# Create the destination folder if it doesn't exist
destination_folder.mkdir(exist_ok=True)

# Construct the new file path
destination_path = destination_folder / file_path.name

try:
# Move the file to the categorized folder
shutil.move(str(file_path), str(destination_path))
print(f"Moved: {file_path.name} → {destination_folder.name}/")
except Exception as e:
print(f"Error moving {file_path.name}: {e}")

print("\n Downloads folder organized successfully!")


if __name__ == "__main__":
# Default path to the user's Downloads folder
user_downloads = str(Path.home() / "Downloads")

print("Automatic Downloads Organizer")
print(f"Target folder: {user_downloads}\n")

# Run the organizer function
organize_downloads(user_downloads)