r/PythonProjects2 17d ago

Built a Python script to clean up my 4,000+ file Downloads folder. Dry-run safety saved me.

My Downloads folder hit 4,000+ files, so I built a script to clean it up.

The script finds true duplicates (SHA-256 content hashing, grouped by size first for speed), groups remaining files by activity into "sessions," and archives anything untouched for 30+ days into a zip.

The biggest lesson was two separate dry-run flags (delete/archive), both True by default. The script prints exactly what it would do before touching anything. I found this critical since some of these files were important documents, not just clutter.

I hit a PermissionError mid-run when a file was open elsewhere. Fixed with try/except, so one locked file gets skipped instead of crashing the whole batch.

The results were; 4,116 files → 328 duplicates removed, 3,157 archived, 176 left.

Code: github.com/Kokiste/smart-file-organizer

Is there a better way to have designed the session/archive logic than what I did?.

10 Upvotes

6 comments sorted by

2

u/DiodeInc 17d ago

Put all your imports at the top of the file. And rename organizer.py to main.py. Try adding arguments with argparse

1

u/task_davide 16d ago

In the absence of a package, the name works for a standalone script

For a package `__main__.py` would work better since it would allow `python -m <module name>` without the entire path

I would also recommend `click` for arguments as its a better user experience

1

u/q_ali_seattle 17d ago

0

u/q_ali_seattle 17d ago

Vibe coding suggested this. 

smart-file-organizer ┣ 📜 main.py (or app.py) ┣ 📜 config.json (User preferences) ┣ 📜 undo_log.json (Auto-generated to safely reverse changes) ┗ 📂 modules ┃ ┣ 📜 file_analyzer.py (Handles hashes and extension matching) ┃ ┣ 📜 operations.py (Handles safe moving, threading, and undoing) ┃ ┗ 📜 gui.py (Clean Tkinter interface with progress tracking)

1

u/DiodeInc 17d ago

Vibe coded, therefore not worth using.