import glob import os import sys import codecs rootdir = "./units" source_encoding = "ANSI" 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 = codecs.open(os.path.join(root, filename), 'r', source_encoding).read() print(u''.join(source)) final = open(os.path.join(root, filename), 'w') print(u''.join(source), file = final) final.close()