import os
import shutil
def 复制文件(源文件路径, 目标文件路径):
source_path = os.path.abspath(源文件路径)
target_path = os.path.abspath(目标文件夹路径)
if not os.path.exists(target_path):
# 如果目标路径不存在原文件夹的话就创建
os.makedirs(target_path)
if os.path.exists(source_path):
# 如果目标路径存在原文件夹的话就先删除
shutil.rmtree(target_path)
shutil.copytree(source_path, target_path)
print('copy dir finished!')
还有一种非原封不动方式,就是把文件夹内的文件拆解出来
参考文章:Python-文件夹的拷贝操作