import os import shutil dr = os.path.abspath('../skins') for fn in os.listdir(dr): if fn.endswith('.js') or fn.endswith('.css'): fn = os.path.join(dr, fn) print "Changing", fn data = open(fn, 'rb').read() # styles clash data = data.replace('comment', 'dp-comment') data = data.replace('dp-dp-comment', 'dp-comment') open(fn, 'wb').write(data)