Organize your messy folders automatically with Python in minutes! This beginner-friendly script sorts files by type, creates folders, and moves everything into place.
- Auto-organize files by extension
- Safe workflow with dry-run mode before moving files
- Timestamped log file to see what changed
- Duplicate file renaming (
file_1,file_2, …) - Optional whitelist/skip extensions
- Works on Windows & macOS
- Python 3.x installed
- Basic command line usage
- A test folder with mixed files to practice
os— file system operationsshutil— move filespathlib— clean path handlingdatetime— timestamped logs
- Clone this repository:
git clone https://github.com/CodeANDCraftHub/FileOrganizer.git
cd FileOrganizer- Make sure your test folder has some mixed files (or use the included
example_folder/).
example_folder/
├── test_image.jpg
├── test_video.mp4
├── test_doc.pdf
├── test_audio.mp3
├── test_script.py
├── test_archive.zip
├── random_file.xyz
├── test_app.exe
- Open
file_organizer.pyand set your folder:
SOURCE_DIR = Path.home() / "Downloads" # or your folder path- Run in dry-run mode first to preview changes:
python file_organizer.py- Check the generated log file to see which files would be moved:
file_organizer_log_YYYYMMDD_HHMMSS.txt
- When ready, set:
dry_run = Falseand run again to actually move files.
- Whitelist extensions to skip certain files:
whitelist_extensions = [".txt", ".md"]- Add/Update file types by editing the
file_typesdictionary in the script.
- Clean Downloads or Desktop clutter
- Batch organize project assets, images, PDFs, and docs
- Keep screenshot folders tidy
- Duplicate files are automatically renamed
- Safe to re-run: only processes files in the root folder
- Works on both Windows and macOS (update folder path format as needed)
Check out my Python screenshot automation tool — automatically timestamps and organizes your screenshots.
- Full script:
file_organizer.py - Example folder:
example_folder/
If this script saved you time, subscribe to Code & Craft Hub on YouTube for more Python automation projects and practical, beginner-friendly scripts.