I Wrote a Python Script That Cleans Up Any Messy Folder — and It Never Deletes Anything by Default
Everyone has that one folder. Downloads, Desktop, some project directory — hundreds of files, no structure, and the thought of sorting it by hand is so dull you just... don't. I wrote a small Python script that does it for you. It sorts a folder's files into subfolders by type, and the important part is in the title: by default, it changes nothing. It only shows you what it would do. You have to…
Ever find yourself in a folder filled with a jumbled mess of files, no discernible organization in sight? I've crafted a Python script to tackle that very issue. It sorts the folder's contents into subfolders based on their type, all without touching a single file by default. Here's how it works and how to use it.
The script categorizes files into six groups: images, documents, spreadsheets, archives, code, and other miscellaneous files. By default, it only displays what it would do, requiring an explicit command to actually move the files. This way, you can preview the changes before making any modifications.
To run the script, simply point it at a folder and execute it. Use the `--apply` flag to initiate the actual file sorting. The script provides a clean, dry-run output, showing which files would be moved and to where. It relies solely on the standard Python library, so there's no need for additional installations.
Here are the categories the script uses:
- Images: .jpg, .jpeg, .png, .gif, .webp, .svg
- Documents: .pdf, .doc, .docx, .txt, .md
- Spreadsheets: .csv, .xls, .xlsx, .ods
- Archives: .zip, .tar, .gz, .rar, .7z
- Code: .py, .js, .html, .css, .json
It's designed to be straightforward and safe. The script won't delete any files, only move them. It won't touch subfolders, ensuring your existing folder structure remains intact. And the best part? No install step is required — just run the script directly.
By running the script with the `--apply` flag, you can quickly and easily organize your files without the hassle of manual sorting.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.