Skip to content

Instantly share code, notes, and snippets.

@ewiger
Created May 26, 2016 14:54
Show Gist options
  • Save ewiger/655c801eccfd98b5bc32008823a4c567 to your computer and use it in GitHub Desktop.
Save ewiger/655c801eccfd98b5bc32008823a4c567 to your computer and use it in GitHub Desktop.
was written this piece of code so often, I decided to put it into a gist
import os
import sys
ROOT = os.path.dirname(os.path.abspath(__file__))
TOKEN = 'No Response Detected'
NEWTOKEN = 'FISH01'
def rename_tiff_folder(tiff_path):
for oldname in os.listdir(tiff_path):
if not (oldname.endswith('.tif') or oldname.endswith('.png')):
continue
if TOKEN not in oldname:
print 'already renamed %s' % oldname
continue
newname = oldname.replace(TOKEN, NEWTOKEN)
oldname = os.path.join(tiff_path, oldname)
newname = os.path.join(tiff_path, newname)
print 'renaming %s -> %s ' % (oldname, newname)
os.rename(oldname, newname)
if __name__ == '__main__':
tiff_path = ROOT
if len(sys.argv) > 1:
tiff_path = sys.argv[1]
assert tiff_path.endswith('TIFF')
rename_tiff_folder(tiff_path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment