Day 18 of 100 Days Coding Challenge: Python
Let’s get one thing straight: I am not a digital Marie Kondo. My desktop often looks like a digital garage sale, and every few weeks, I muster the courage to face it—dragging files around like I’m playing a very boring version of Tetris. I usually go the old-fashioned route: click, drag, sort, sigh. Then, one day, while sorting my pictures, I thought… Wait a minute. I know Python. Why am I doing this with my human hands? So, I decided to create a Python file organizer script to organize my pictures.
Today’s Motivation / Challenge
Today’s project tackles a common monster: messy folders. Whether it’s your Downloads folder, your project archive, or that strange desktop abyss, the pain is universal. The challenge? Build a simple, no-fuss tool that does the sorting for you—like a digital butler who doesn’t judge your file-naming habits.
Purpose of the Code (Object)
This little script organizes all the files in a selected folder by their file extensions. That means all your .jpg files go to the “jpg” folder, .pdf files go to the “pdf” folder, and your .who-knows files? They get a home too. It’s your personal assistant for decluttering—minus the hourly rate.
AI Prompt:
Python code to organize files in a folder by their file extension. Include a GUI for folder selection and an undo function to reverse the operation.
Functions & Features
- Sorts files by extension into neat subfolders
- Ignores folders and only targets loose files
- GUI-based folder selection (no need to type paths)
- Undo function to restore files to original locations
Requirements / Setup
- Python 3.6+
No pip installs required—just your standard library.
Minimal Code Sample
python
CopyEdit
ext = ext[1:].lower() or “no_extension”
dest = os.path.join(folder_path, ext)
shutil.move(file_path, os.path.join(dest, filename))
This sorts each file into a folder named after its extension.
Notes / Lessons Learned
This time, I couldn’t resist poking the code like a cat with a suspicious shoelace. I renamed ChatGPT to “Mrs. Cat” just to see if she’d organize with more sass (she didn’t). Then I fed the script a folder full of chaos—downloads, screenshots, and whatever that .swf file was. Everything got tucked neatly into place. The thrill of seeing it work was only topped by the dread of realizing I’d just hidden all my junk into different corners. So, naturally, I added an undo button. Because sometimes, you need to imagine the consequences before you automate your mess.
Optional Ideas for Expansion
- Add a “preview before sort” function so you can see what’s about to move
- Let users customize folder names (e.g., “Images” instead of “jpg”)
- Add a cleanup timer to auto-organize your folder once a week
