A Python utility that automatically organizes files into categorical directories based on their extensions. Features smart directory management, undo functionality, and detailed operation logging.
- Organizes files by type into appropriate directories
- Creates directories only when needed (no empty folders)
- Handles file naming conflicts automatically
- Maintains original file names with numeric suffixes for duplicates
- Pre-configured categories for common file types:
- Images (.jpg, .jpeg, .png, .gif, etc.)
- Documents (.pdf, .doc, .docx, .txt, etc.)
- Audio (.mp3, .wav, .flac, etc.)
- Video (.mp4, .avi, .mkv, etc.)
- Archives (.zip, .rar, .7z, etc.)
- Code (.py, .js, .html, etc.)
- Custom rule support using regex patterns
- Miscellaneous category for unmatched files
- Undo last operation
- Undo all operations
- Automatic cleanup of empty directories
- Persistent operation history
- Detailed operation logging
- Clone the repository:
git clone https://github.com/yourusername/file-organizer.git
cd file-organizer- No external dependencies required - uses Python standard library only!
file-organizer/
├── file_organizer.py # Core classes and functionality
├── main.py # Command-line interface
├── .gitignore # Git ignore rules
└── README.md # This file
from file_organizer import FileOrganizer
# Initialize organizer
organizer = FileOrganizer("/path/to/directory")
# Organize files
organizer.organize_files()Run the program:
python main.pyThe interactive menu provides options to:
- Organize files
- Undo last operation
- Undo all operations
- Show operation history
- Add custom rules
- Cleanup empty directories
- Exit
organizer = FileOrganizer("/path/to/directory")
organizer.add_custom_rule(r'\.log$', 'logs') # Move all .log files to 'logs' directory# Add new category
organizer.add_extension_category('ebooks', ['.epub', '.mobi', '.azw3'])
# Get category for a file
category = organizer.get_category('.pdf')- Creates timestamped log files
- Logs all file operations
- Tracks directory creation and removal
- Maintains operation history for undo functionality
- Only creates directories that will be used
- Automatically removes empty directories after undo
- Prevents directory clutter
- Handles nested directories properly
- Saves operation history to JSON
- Persists between sessions
- Allows for operation auditing
- Supports undo functionality
from file_organizer import FileOrganizer
# Initialize
organizer = FileOrganizer("~/Downloads")
# Add custom rule for project files
organizer.add_custom_rule(r'\.project$', 'projects')
# Organize files
organizer.organize_files()
# Oops! Undo last operation if needed
organizer.undo_last()
# View operation history
history = organizer.get_operation_history()
for entry in history:
print(f"Moved {entry['file']} to {entry['to']}")- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Maintain Python standard library independence
- Add tests for new features
- Update documentation
- Follow PEP 8 style guidelines
- More supported file types
- GUI interface
- Advanced file type detection
- Content-based organization
- Multi-threading support
- Scheduled organization
- File type previews
- Organization templates
Distributed under the MIT License. See LICENSE for more information.
For support, please open an issue in the GitHub repository.