2008年9月16日火曜日

change encoding with python


#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import re

if __name__ == "__main__":
base_dir = os.getcwd()
filter = re.compile('\.h$|\.m$|\.cpp$|\.c$')
for dirpath, dirnames, filenames in os.walk(base_dir):
for filename in filenames:
if filter.search(filename):
p = os.path.join(dirpath, filename)
action = 'nkf --utf8 %s > %s_' % (p, p)
os.system(action)
action = 'mv %s_ %s' % (p, p)
os.system(action)

0 件のコメント: