Day 13 of 100 Days Coding Challenge: Python
Have you ever dumped a bunch of photos from your phone or camera onto your computer, only to be greeted by a wall of files named IMG_2034 or DSC_0198? That was me last week. Weād just come back from visiting my dad in Indiana, and I spent hours renaming photos just so Iād know what was what later. By hour three, I started questioning my life choices.
Todayās app was born out of that chaos. Itās for anyone whoās ever opened their Downloads folder and felt genuine fear. You know the sceneāscreenshot(385).png, resume_final_final_really_FINAL.docx, and misc.zip (which, letās be honest, contains nothing but regret).
Eventually, I snapped. I built a File Renamer. Because at some point, every coder realizes the real enemy isnāt broken codeāitās bad file names. My little app brought order to the madness, one underscore at a time. Justice was served. Silently.
Todayās Motivation / Challenge
File naming seems trivialāuntil it isnāt. Whether itās organizing screenshots, exported reports, or the fifth version of your side projectās logo, weāve all played the ārename, regret, repeatā game. This challenge gave me a chance to bring order to chaos, while flexing my Python skills in a way that solves a real, everyday annoyance. Plus, thereās something oddly satisfying about watching a folder transform from digital dumpster to methodical masterpiece.
Purpose of the Code (Object)
This Python app batch-renames files in a folder using a pattern you chooseālike photo_1.jpg, photo_2.jpg, and so on. It lets you preview changes, filter by file type, and confirm before anything happens. The final version even adds an undo option and keeps a time-stamped log of renamed files.
AI Prompt:
āPlease create a Python code File renamer.ā
āCan you add the following function to the GUI version? #Add an undo feature #Add a log file to save old/new names.”
Functions & Features
- Select a folder with a file dialog (no more mistyped paths)
- Set custom prefix and starting number
- Filter files by extension (e.g., .txt, .jpg)
- Preview all renaming before it happens
- Automatically log all rename operations with a timestamp
- Undo your most recent renaming session
Requirements / Setup
- Python 3.6+
- No extra libraries needed (just tkinter, which comes with Python)
Minimal Code Sample
for i, file in enumerate(files, start=start_number):
ext = os.path.splitext(file)[1]
new_name = f”{prefix}{i}{ext}”
os.rename(os.path.join(folder_path, file), os.path.join(folder_path, new_name))
This is where the magic happens: renaming each file while keeping its original extension.
Notes / Lessons Learned
So all your files become lovely, logical things like file_1.txt, file_2.txt, and file_3.txt. It was beautiful. It was organized. It was⦠terrifyingly powerful. Thatās when I remembered something crucial: I never get folder paths right. Backslashes, forward slashes, hidden Unicode weirdnessāmy fingers always betray me.
So I thought, āLetās make this a GUI.ā Because honestly, why should I suffer when I can just click a folder like a functioning adult?
New version, new vibe. It had buttons. It had folder selection dialogs. It even had a preview feature, like the app was politely saying, āHereās what youāre about to do. You sure about this?ā If there were no files to rename, it didnāt throw a tantrumāit simply shrugged and bowed out.
And just when I thought it was ādone,ā I asked myself:
What if I mess this up?
Enter: undo button and activity log.
Because if weāre going full Renamer Pro Modeā¢, I want receipts. I added:
- A complete log of what each file used to be called
- A timestamp of when the operation occurred
- An undo feature, because Iām not about to manually rename everything back like itās 2003
Once I tested everything (successfully, I might addāzero casualties), I realized something strange and wonderful:
This tiny project gave me an idea for improving a workflow at my day job. Turns out, renaming a bunch of files can actually inspire how to batch-handle documents in Power Automate. Who knew?
Oh, and one last grown-up move: I finally added a license to the project.
Hereās what I learned:
A License Type
- MIT: Super chill. Basically says, āTake it, use it, remix itājust donāt sue me.ā
- GPL: More of a Robin Hood. If you improve it, you share it.
- Apache 2.0: Like MIT but with a legal helmet.
- No License: Says, āIām not ready for commitment.ā Basically off-limits.
I went to MIT because this little renamer deserves to be free.
Optional Ideas for Expansion
- Add a ādry runā mode to simulate renaming without touching files
- Add support for multiple undo steps (not just one session)
- Export the log as a CSV file for spreadsheet nerds (no judgment)
