Python实现压缩解压缩,移动复制copy文件

import shutil
import os
from shutil import make_archive


# 查看可压缩的文件类型
print(shutil.get_archive_formats())
# 压缩文件原始与压缩文件存放的根目录
rootPath = r'F:/BaiduNetdiskDownload/COVID-19CTSeg/3DUNet-Pytorch/test'
# 压缩文件存放目录
# Myarchive:压缩文件名
# archive_name = os.path.expanduser(os.path.join(rootPath, 'Myarchive'))
# # 被压缩文件路径
# root_dir = os.path.expanduser(os.path.join(rootPath, ''))
# make_archive(archive_name, 'gztar', root_dir)

# copyfile
from shutil import copyfile
from shutil import copytree
import logging

def _logpath(path, names):
    logging.info('Working in %s', path)
    return []   # nothing will be ignored
source = r'F:/BaiduNetdiskDownload/COVID-19CTSeg/3DUNet-Pytorch/label'
destination = r'F:/BaiduNetdiskDownload/COVID-19CTSeg/3DUNet-Pytorch/test'
copytree(source, destination, ignore=_logpath)

# https://docs.python.org/3/library/shutil.html?highlight=copyfile#shutil-platform-dependent-efficient-copy-operations
posted @ 2020-03-26 13:52  DuanYongchun  阅读(622)  评论(0编辑  收藏  举报