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!
-
π Automated File Sorting
Sorts files into predefined categories likeImages,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.
Save the script as file_organizer.py or any filename ending in .py.
Navigate to the folder where the script is located:
cd /path/to/your/script/folderRun the script with Python:
python file_organizer.pyThe 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.
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.
The categorization logic is based on the extension_to_folder dictionary inside the organize_files function.
extension_to_folder.update({
'.csv': 'Spreadsheets',
'.xlsx': 'Spreadsheets',
# Add more as needed
})extension_to_folder.update({
'.zip': 'CompressedFiles', # Changed from 'Archives'
})Any files with extensions not explicitly mapped will go into the Others folder by default.
- Python 3.x
osβ Directory and file path operationsshutilβ High-level file operationscollections.defaultdictβ Flexible category mapping
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
This project is open-source and free to use.
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.
Thanks to the Python standard library for making scripting easy and powerful!
Happy organizing! π§Ήπ