zoukankan      html  css  js  c++  java
  • shutil模块,ZipFile 和 TarFile 两个模块

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

    shutil.copyfileobj(fsrc, fdst[, length])
    将文件内容拷贝到另一个文件中,可以部分内容

    shutil.copyfile(src, dst)
    拷贝文件

    shutil.copymode(src, dst)
    仅拷贝权限。内容、组、用户均不变,

    shutil.copystat(src, dst)
    拷贝状态的信息,包括:mode bits, atime, mtime, flags

    只拷贝修改时间和访问时间,其他不拷贝,包括权限和创建时间

    shutil.copy(src, dst)
    拷贝文件和权限

    shutil.copy2(src, dst)
    拷贝文件和状态信息

    shutil.ignore_patterns(*patterns)
    shutil.copytree(src, dst, symlinks=False, ignore=None)
    递归的去拷贝文件,这里test4,new_test4的源目标都是目录

    例如:copytree(source, destination, ignore=ignore_patterns('*.pyc', 'tmp*'))

    shutil.rmtree(path[, ignore_errors[, onerror]])
    递归的去删除文件和目录

     

    shutil.move(src, dst)
    递归的去移动文件

    shutil.make_archive(base_name, format,...)

    创建压缩包并返回文件路径,例如:zip、tar

    base_name: 压缩包的文件名,也可以是压缩包的路径。只是文件名时,则保存至当前目录,否则保存至指定路径,
    如:www =>保存至当前路径
    如:/Users/wupeiqi/www =>保存至/Users/wupeiqi/
    format: 压缩包种类,“zip”, “tar”, “bztar”,“gztar”
    root_dir: 要压缩的文件夹路径(默认当前目录)
    owner: 用户,默认当前用户
    group: 组,默认当前组
    logger: 用于记录日志,通常是logging.Logger对象

    shutil 对压缩包的处理是调用 ZipFile 和 TarFile 两个模块来进行的,详细:

     shutil.make_archive是对文件夹进行压缩,ZipFile是对文件进行压缩

  • 相关阅读:
    解决SharePoint 2010拒绝访问爬网内容源错误
    Sharepoint 2010 工作流状态值
    修改任务显示WrkTaskIp.aspx页面
    Infopath 2013 通过UserProfileService读取AD用户信息
    js验证
    .net中下载文件的方法(转)
    IIS限制ASP.Net 文件上传大小解决方案,修改IIS7/7.5配置
    SharePoint2013 SharePoint-Hosted 模式 分页方法
    技术QQ群
    react学习
  • 原文地址:https://www.cnblogs.com/itfat/p/7486997.html
Copyright © 2011-2022 走看看