File Organizer Project Expanded
File Organizer Project Expanded
### Objectives
- To develop a script that automatically organizes files into categories such as Images,
Documents, and Music.
- To simplify the process of locating files by grouping them logically.
- To reduce the time spent on manual file sorting.
- To provide a customizable and scalable solution for personal and professional file
management.
2. Features
1. **Automatic Sorting**: Automatically organizes files based on file extensions.
2. **Dynamic Folder Creation**: Creates necessary folders dynamically if they don’t exist.
3. **Support for Various File Types**: Recognizes file extensions like `.jpg`, `.png`, `.pdf`,
`.mp3`.
4. **Error Handling**: Files with unknown extensions are moved to an 'Others' folder.
5. **Cross-Platform Compatibility**: Runs on Windows, macOS, and Linux without
modifications.
6. **Scalability**: Handles directories with thousands of files efficiently.
3. Technologies Used
The File Organizer leverages Python's simplicity and powerful libraries to provide a robust
file organization tool. Key technologies used include:
- **Python**: Chosen for its flexibility and rich ecosystem.
- **os Module**: For interacting with the file system (e.g., directory creation, file iteration).
- **shutil Module**: Facilitates moving files between directories.
4. System Design and Architecture
### High-Level Architecture
- Input: A directory path provided by the user.
- Process: Analyze file extensions, classify files, and move them into corresponding folders.
- Output: A well-organized directory structure.
### Flowchart
*(Insert Flowchart Here)*
5. Code Walkthrough
The File Organizer script is designed to be simple yet powerful. Below is a detailed
explanation of its components.
**Code Snippet:**
import os
import shutil
FILE_CATEGORIES = {
"Images": [".jpg", ".jpeg", ".png", ".gif", ".bmp", ".tiff"],
"Documents": [".pdf", ".doc", ".docx", ".txt", ".ppt", ".pptx", ".xls", ".xlsx"],
"Videos": [".mp4", ".mkv", ".mov", ".avi", ".flv"],
"Music": [".mp3", ".wav", ".aac", ".flac"],
"Archives": [".zip", ".rar", ".tar", ".gz", ".7z"],
"Code": [".py", ".js", ".html", ".css", ".java", ".c", ".cpp", ".rb", ".php"],
"Others": []
}
def organize_files(directory):
if not os.path.exists(directory):
print(f"The directory '{directory}' does not exist.")
return
print(f"Organizing files in: {directory}")
file_extension = os.path.splitext(filename)[1].lower()
moved = False
for category, extensions in FILE_CATEGORIES.items():
if file_extension in extensions:
shutil.move(file_path, os.path.join(directory, category, filename))
moved = True
break
if not moved:
shutil.move(file_path, os.path.join(directory, "Others", filename))