#!/usr/bin/env python """ load modules """ import os import sys """ What dir are we listing? """ target_dir = sys.argv[1] """ Build dict """ rename_map = dict((k,v) for (k,v) in [ (x, ''.join([ y.strip('[]()') for y in x ]).replace(' ','_')) for x in os.listdir('.') ]) """ For safetey reasons, print out the 'mv' commands that need to be run. These could easily be swapped for a call to 'os.rename()' """ for (k,v) in rename_map.items(): sys.stdout.write("mv -v '%s' %s\n" % (k, v)) sys.exit(0)