注意下面代码中的dst目录在运行之前不存在。
import os.path as osp
import os
import shutil
def fun(src, dst):
if osp.exists(dst):
pass
else:
shutil.copytree(src, dst)
for root, dirs, files in os.walk(dst):
for file in files:
path = osp.join(root, file)
a, b = osp.splitext(path)
if (b == '.h' or b == '.cpp'):
try:
with open(path, 'r', encoding='gbk') as f:
data = f.read()
with open(path, 'w', encoding='utf-8') as f:
f.write(data)
except:
print(path)
if __name__ == '__main__':
src = r"E:\代码\qt-master\360SafeDemo"
dst = r"F:\python\360SafeDemo"
fun(src, dst)