Skip to content

Instantly share code, notes, and snippets.

@yin8086
Created May 20, 2013 09:29
Show Gist options
  • Save yin8086/5611262 to your computer and use it in GitHub Desktop.
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
# -*- 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