Skip to content

The Python File Organizer & Sorter is a command-line tool that helps declutter and organize your files with ease.

Notifications You must be signed in to change notification settings

prvcds/file-organizer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

7 Commits
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“ Python File Organizer & Sorter

The Python File Organizer & Sorter is a command-line tool that helps declutter and organize your files with ease. It scans a specified directory and automatically moves files into categorized subfolders based on their file extensionsβ€”making your digital life a lot cleaner!


πŸš€ Features

  • πŸ”„ Automated File Sorting
    Sorts files into predefined categories like Images, Documents, Videos, Audio, Code, and more.

  • πŸ› οΈ Customizable Categories
    Easily update the extension-to-folder mappings to suit your personal or project-specific needs.

  • 🧱 Robust Error Handling
    Handles invalid paths, permission errors, and duplicate file names gracefully without crashing.

  • πŸ–₯️ Intuitive CLI
    Prompts guide users to input the directory path for organization.

  • πŸ“‹ Movement Logs
    Real-time feedback shows which files are moved and to which folders.


πŸ“¦ How to Use

1. Save the Script

Save the script as file_organizer.py or any filename ending in .py.

2. Open Terminal / Command Prompt

Navigate to the folder where the script is located:

cd /path/to/your/script/folder

3. Run the Script

Run the script with Python:

python file_organizer.py

4. Enter Directory Path

The script will prompt you to enter the full path of the directory you want to organize. Examples:

  • Windows: C:\Users\YourUser\Downloads
  • macOS/Linux: /home/youruser/Downloads

Type the path and press Enter. You can also type exit to quit the program.

5. Watch the Magic ✨

The script will begin processing files, creating category folders (if they don’t already exist), and moving files accordingly. You'll see real-time logs of all movements in your terminal.


πŸ”§ Customization

The categorization logic is based on the extension_to_folder dictionary inside the organize_files function.

βž• Add New Categories

extension_to_folder.update({
    '.csv': 'Spreadsheets',
    '.xlsx': 'Spreadsheets',
    # Add more as needed
})

✏️ Modify Existing Mappings

extension_to_folder.update({
    '.zip': 'CompressedFiles',  # Changed from 'Archives'
})

πŸ“‚ Default β€œOthers” Category

Any files with extensions not explicitly mapped will go into the Others folder by default.


πŸ§ͺ Technologies Used

  • Python 3.x
  • os – Directory and file path operations
  • shutil – High-level file operations
  • collections.defaultdict – Flexible category mapping

⚠️ Error Handling

This script includes multiple safeguards to ensure smooth operation:

  • βœ… Validates input directory paths
  • βœ… Automatically creates missing category folders
  • βœ… Avoids overwriting existing files (adds suffix like file(1).txt)
  • βœ… Catches permission and file movement errors

πŸ“ƒ License

This project is open-source and free to use.


🀝 Contributing

Feel free to fork this repository and open a pull request if you want to improve the script, add more categories, or enhance its features.


πŸ™Œ Acknowledgments

Thanks to the Python standard library for making scripting easy and powerful!


Happy organizing! πŸ§ΉπŸ“‚

About

The Python File Organizer & Sorter is a command-line tool that helps declutter and organize your files with ease.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages