shutil模块

shutil模块:高级的 文件、文件夹、压缩包 处理模块

# 基于路径的文件复制:
shutil.copyfile('source_file', 'target_file')

# 基于流的文件复制:
with open('source_file', 'rb') as r, open('target_file', 'wb') as w:
shutil.copyfileobj(r, w)

# 递归删除目标目录
shutil.rmtree('target_folder')

# 文件移动
shutil.move('old_file', 'new_file')

# 文件夹压缩
shutil.make_archive('file_name', 'format', 'archive_path')

# 文件夹解压
shutil.unpack_archive('unpack_file', 'unpack_name', 'format')

原文地址:https://www.cnblogs.com/zhangdajin/p/11140966.html