Created
May 20, 2013 09:29
-
-
Save yin8086/5611262 to your computer and use it in GitHub Desktop.
Recursively translate all the C++ file from gbk codecs to utf-8 codecs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
Created on Mon May 20 16:15:32 2013 | |
@author: Yinxy | |
""" | |
import os, fnmatch | |
for pathName, dirNames, fileNames in os.walk('.'): | |
print pathName | |
for fileName in fileNames: | |
print '\t' + fileName | |
if fnmatch.fnmatch(fileName, '*.cpp') \ | |
or fnmatch.fnmatch(fileName, '*.c') \ | |
or fnmatch.fnmatch(fileName, '*.h'): | |
with open(os.path.join(pathName, fileName), 'rb') as fin: | |
myStr = fin.read() | |
with open(os.path.join(pathName, fileName), 'wb') as fout: | |
fout.write(myStr.decode('GBK').encode('utf-8')) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment