An asynchronous Python application that sorts files by their extensions into organized subdirectories. This tool efficiently processes large numbers of files concurrently, making file organization fast and reliable.
- Asynchronous Processing: Uses Python's
asynciofor concurrent file operations - Extension-based Sorting: Automatically organizes files into folders based on their file extensions
- Conflict Resolution: Handles duplicate filenames by adding numeric suffixes
- Comprehensive Logging: Logs operations to both file and console
- Error Handling: Robust error handling for file operations and edge cases
- Recursive Processing: Processes all files in subdirectories recursively
-
Clone or download this repository
-
Create and activate a virtual environment:
python3 -m venv .venv source .venv/bin/activate -
Install the required dependencies:
pip install -r requirements.txt
python3 main.py <source_folder> <output_folder>-
Sort files from Documents to SortedFiles:
python3 main.py ~/Desktop/m-power ~/Desktop/sorted-files
-
Sort files with absolute paths:
python3 main.py /path/to/messy/folder /path/to/organized/folder
-
Sort current directory files:
python3 main.py . ./sorted_files
source: Path to the source folder containing files to sortoutput: Path to the output folder where sorted files will be placed
- Scanning: The application recursively scans the source folder for all files
- Extension Detection: Each file's extension is extracted (files without extensions go to 'no_extension' folder)
- Directory Creation: Creates subdirectories in the output folder based on file extensions
- Asynchronous Copying: Files are copied concurrently using async operations
- Conflict Resolution: If files with the same name exist, numeric suffixes are added (e.g.,
file_1.txt,file_2.txt)
The application organizes files into the following structure:
output_folder/
├── txt/
│ ├── document1.txt
│ └── document2.txt
├── jpg/
│ ├── photo1.jpg
│ └── photo2.jpg
├── pdf/
│ ├── manual.pdf
│ └── report.pdf
├── no_extension/
│ └── README
└── ...
The application creates detailed logs in two locations:
- Console output: Real-time progress and status updates
- Log file:
file_sorter.login the current directory with detailed operation history
Log entries include:
- Successful file copies with source and destination paths
- Error messages for failed operations
- Process start and completion notifications
The application handles various error scenarios:
- Non-existent source folders
- Permission issues
- File access errors during copying
- Invalid path specifications
The async implementation allows for:
- Concurrent file operations
- Efficient processing of large file collections
- Non-blocking I/O operations
- Scalable performance based on system resources
2025-06-07 17:01:49,876 - INFO - Starting file sorting from /Users/admin/Desktop/m-power to /Users/admin/Desktop/sorted-files
2025-06-07 17:01:49,881 - INFO - Copied /Users/admin/Desktop/m-power/other/Ковальчук_РА.zip to /Users/admin/Desktop/sorted-files/zip/Ковальчук_РА.zip
2025-06-07 17:01:49,882 - INFO - Copied /Users/admin/Desktop/m-power/other/Одноразова рада.txt to /Users/admin/Desktop/sorted-files/txt/Одноразова рада.txt
2025-06-07 17:01:49,882 - INFO - Copied /Users/admin/Desktop/m-power/Ковальчук_РА.zip to /Users/admin/Desktop/sorted-files/zip/Ковальчук_РА.zip
2025-06-07 17:01:49,882 - INFO - Copied /Users/admin/Desktop/m-power/.DS_Store to /Users/admin/Desktop/sorted-files/no_extension/.DS_Store
2025-06-07 17:01:49,882 - INFO - Copied /Users/admin/Desktop/m-power/Знімок екрана 2025-04-05 о 17.20.06.png to /Users/admin/Desktop/sorted-files/png/Знімок екрана 2025-04-05 о 17.20.06.png
2025-06-07 17:01:49,883 - INFO - File sorting completed
-
Permission Denied
- Ensure you have read permissions for the source folder
- Ensure you have write permissions for the output folder
-
Module Not Found Error
- Install the required dependencies:
pip install -r requirements.txt
- Install the required dependencies:
-
Source Folder Not Found
- Verify the source folder path exists and is accessible
- Use absolute paths if relative paths cause issues
If you encounter issues:
- Check the
file_sorter.logfile for detailed error messages - Ensure all file paths are valid and accessible
- Verify Python version compatibility (3.7+)
This project is open source and available under the MIT License.