Last active
May 18, 2020 08:44
-
-
Save zhaofeng-shu33/2c008b01e3d5104faa0817ab05f39e1c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import os | |
import argparse | |
def convert(filename): | |
with open(filename, 'rb') as f: | |
st = f.read() | |
try: | |
st = st.decode('gbk') | |
except Exception as e: | |
print('gbk decode error for ' + filename) | |
return | |
with open(filename, 'wb') as f: | |
f.write(st.encode('utf-8')) | |
if filename.find(' ') > 0: | |
os.rename(filename, filename.replace(' ', '_')) | |
def parse_all(ext): | |
for i in os.listdir('./'): | |
if i.find('.' + ext) > 0: | |
convert(i) | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser() | |
parser.add_argument('--type', default='txt') | |
args = parser.parse_args() | |
parse_all(args.type) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment