MATLAB的.m文件使用iconv工具在windows和linux平台下编码的批量转换
程序员文章站
2022-03-28 18:25:19
# -*- coding: utf-8 -*- #!/bin/python import os import sys def TransCode(rootpath, pattern): for root, dirs, files in os.walk(rootpath): for file_ in ......
# -*- coding: utf-8 -*-
#!/bin/python
import os
import sys
def TransCode(rootpath, pattern):
for root, dirs, files in os.walk(rootpath):
for file_ in files:
if file_.endswith("m"):
file_name = os.path.join(root, file_)
dst = 'result/' + root
if pattern == 'windows':
os.system('mkdir -p ' + dst)
os.system('iconv ' + file_name + ' -f utf8 -t gbk -c -s > ' + dst + '/' + file_)
elif pattern == 'linux':
os.system('mkdir -p ' + dst)
os.system('iconv ' + file_name + ' -f gbk -t utf8 -c -s > ' + dst + '/' + file_)
else:
print 'error type'
exit(1)
if __name__ == '__main__':
print sys.argv[0]
print sys.argv[1]
print sys.argv[2]
TransCode(*sys.argv[1:3])
exit(0)
usage: python XXX.py rootpath to_platform