PythonStudy——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')

# 文件夹压缩
# file_name:被压缩后形成的文件名  format:压缩的格式  archive_path:要被压缩的文件夹路径
shutil.make_archive('file_name', 'format', 'archive_path')

# 文件夹解压
# unpack_file:被解压文件 unpack_name:解压后的名字 format解压格式
shutil.unpack_archive('unpack_file', 'unpack_name', 'format')

 

posted @ 2019-05-08 20:27  挺锅锅  阅读(93)  评论(0编辑  收藏  举报