Quick File Renaming With Python for any OS

I use this trick all the time.

Finding a convenient and handy file renamer I guess wasn’t that fruitful, but I have used this python trick more times than I can count.

Also, this might just be me, but bash one liners while cute and handy are sometimes just super hard to read, and therefore troubleshoot,

Bash doesn’t work on Windows, unless I’m using git bash, which is always slightly different from regular bash,

Python works pretty much the same however on both Mac and Windows.

cd into the folder where you want to do the renaming.

Type “python” to enter the python terminal, ie. open a Python session

import os, globfor file in glob.glob("*.*"):
os.rename(file, file.replace("old", "new"))

use exit() to exit your Python session.

So handy!!

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store