Skip to content

Instantly share code, notes, and snippets.

@jskeates
Forked from snodnipper/rename.py
Last active August 29, 2015 14:10
Show Gist options
  • Save jskeates/1c7dc14c077d9ea5808b to your computer and use it in GitHub Desktop.
Save jskeates/1c7dc14c077d9ea5808b to your computer and use it in GitHub Desktop.
#! /usr/bin/python
import os, os.path, re
counter = 0
for root, _, files in os.walk("./"):
for f in files:
fullpath = os.path.join(root, f)
replaced = re.sub("_OST50GRID\w*", "", f)
newfullpath = os.path.join(root, replaced)
if fullpath != newfullpath:
print 'Renamed: "' + fullpath + '" to "' + newfullpath
counter += 1
os.rename(fullpath, newfullpath)
print 'Done. Renamed ' + str(counter) + ' files.'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment