import glob import os import sys import codecs rootdir = "./" source_encoding = "ISO-8859" target_encoding = "utf-8" for root, subdirs, files in os.walk(rootdir): for filename in files: if filename[-4:] == ".txt": print(os.path.join(root, filename)) source = open(os.path.join(root, filename), 'r').read() print(u''.join(source)) final = codecs.open(os.path.join(root, filename), 'w', target_encoding) print(u''.join(source), file = final) final.close()