0% found this document useful (0 votes)
16 views

File Organizer Project Expanded

Uploaded by

bcakalonda
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

File Organizer Project Expanded

Uploaded by

bcakalonda
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

File Organizer Project

A Python-based project to automate file organization.

Submitted by: [Your Name]

Date: [Submission Date]


1. Introduction and Objectives
The File Organizer project addresses a common issue in the digital age—managing
unorganized files in directories. With the increasing amount of data, manually sorting files
is time-consuming and prone to errors. This project introduces an automated system to
classify files based on their extensions and organize them into predefined categories such as
Images, Documents, Videos, Music, Archives, Code, and Others.

### 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.

### File Categories Setup

A dictionary defines categories and their extensions:


```
FILE_CATEGORIES = {
'Images': ['.jpg', '.jpeg', '.png'],
'Documents': ['.pdf', '.docx'],
'Others': []
}
```

### Function: organize_files

This function handles the main logic of the script:


- Validates the input directory.
- Creates necessary folders.
- Iterates through files and moves them based on extensions.
- Handles unrecognized file types.

**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}")

for category in FILE_CATEGORIES.keys():


folder_path = os.path.join(directory, category)
os.makedirs(folder_path, exist_ok=True)

for filename in os.listdir(directory):


file_path = os.path.join(directory, filename)
if os.path.isdir(file_path):
continue

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))

print(f"Organization completed in: {directory}")


6. User Guide
1. Save the script as `file_organizer.py`.
2. Run the script in a terminal:
```bash
python file_organizer.py
```
3. Enter the directory path when prompted.
4. Review the organized folders in the directory.

You might also like