import os
import shutil
import compileall
import time
# 递归删除文件夹中所有类型的文件
def del_file(filepath, file_type='.py'):
files = os.listdir(filepath)
for file in files:
full_path = os.path.join(filepath, file)
if os.path.isfile(full_path):
if full_path.endswith(file_type):
os.remove(full_path)
else:
del_file(full_path)
if __name__ == '__main__':
source_path = os.path.abspath('./sample')
target_path = os.path.abspath('./bin/sample')
shutil.rmtree('./bin',)
os.makedirs('./bin')
print('所有文件删除完成')
time.sleep(2)
shutil.copytree(source_path, target_path)
shutil.copytree('./Config', './bin/Config')
shutil.copyfile('./__main__.py', './bin/__main__.py')
print('copy dir finished!')
compileall.compile_dir('./bin/', maxlevels=2, legacy=True)
del_file('./bin/')
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)