File Organizer
Project Overview
The File Organizer is a powerful Python application designed to automatically sort and organize files based on their types and modification dates. Built with a user-friendly Tkinter interface, this tool helps maintain a clean and structured file system by categorizing files into appropriate folders, handling duplicates intelligently, and providing visual feedback through progress tracking.
Interactive Demo
Try out a simulation of the File Organizer below. Click "Organize Files" to see how different file types would be sorted into folders.
Features
Date-Based Organization
Organizes files into year, month, and week folders based on their modification dates for a chronological structure.
Type-Based Classification
Categorizes files into folders by type (images, documents, audio, video, archives, etc.) for easy access.
Duplicate Handling
Intelligently identifies and handles duplicate files to prevent overwrites and data loss.
Graphical Interface
User-friendly Tkinter GUI makes the tool accessible to users of all technical backgrounds.
Progress Tracking
Visual progress indicators keep you informed about the organization process and completion status.
Empty Folder Cleanup
Optional removal of empty folders after organization to maintain a clean directory structure.
How It Works
The File Organizer processes files through several key steps:
- Scanning: First, it scans the specified directory to identify all files for organization.
- Classification: Each file is classified based on its extension type (image, document, audio, etc.).
- Date Analysis: The modification date of each file is examined to determine its chronological placement.
- Folder Creation: Required folder structures are automatically created based on file types and dates.
- File Movement: Files are moved to their appropriate destination folders while checking for duplicates.
- Cleanup: Optionally, empty folders are removed from the directory structure.
Technical Implementation
The File Organizer is built with Python and leverages several key libraries:
Core Components
- os and shutil: For file system operations and file movement
- datetime: For handling file dates and temporal organization
- tqdm: For visual progress tracking with a progress bar
- Tkinter: For creating the graphical user interface
- re: For regular expression pattern matching to identify duplicates
Key Functions
The organize_files function handles the core organization logic:
def organize_files(directory, delete_empty_folders=False, progress_callback=None):
folders = {
'images': ['.jpg', '.jpeg', '.png', '.gif', '.bmp'],
'documents': {
'word': ['.doc', '.docx'],
'excel': ['.xls', '.xlsx'],
'pdf': ['.pdf'],
'text': ['.txt'],
'ppt': ['.ppt', '.pptx']
},
'audio': ['.mp3', '.wav', '.aac'],
'video': ['.mp4', '.mov', '.avi'],
'archives': ['.zip', '.rar', '.tar', '.gz'],
'scripts': ['.py', '.js', '.sh'],
'installers': ['.exe', '.msi', '.dmg'],
'setups': ['setup.exe', 'setup.msi']
}
for folder in folders:
folder_path = os.path.join(directory, folder)
if not os.path.exists(folder_path):
os.makedirs(folder_path)
The duplicate detection function uses regular expressions to identify common duplicate patterns:
def is_duplicate(file1, file2):
base1 = re.sub(r'\(\d+\)', '', file1)
base2 = re.sub(r'\(\d+\)', '', file2)
return base1.strip() == base2.strip()
How to Use
- Launch the application by running the Python script
- Click "Select Directory" to choose the folder you want to organize
- Choose whether to delete empty folders after organization
- Wait for the organization process to complete
- Explore your newly organized file system
Applications
The File Organizer is ideal for various scenarios:
- Organizing cluttered Downloads folders
- Sorting large photo collections by date
- Managing document libraries
- Cleaning up project directories
- Preparing file systems for archiving or backup
- Maintaining well-structured shared folders in team environments
Back to Projects