zoukankan      html  css  js  c++  java
  • shutil

    shutil

    高级的文件,文件夹,压缩包的处理模块,也主要用于文件的拷贝

    将文件内容拷贝到另一个文件中

    shutil.copyfileobj(fsrc, fdst[, length])

    import shutil
    shutil.copyfileobj(open('old.xml','r'), open('new.xml','w'))
    

    拷贝文件

    shutil.copyfile(src, dst)

    shutil.copyfile('f1.log','f2.log') #目标文件无需存在
    

    仅拷贝权限。内容、组、用户均不变

    shutil.copymode(src, dst)

    shutil.copymode('f1.log','f2.log')#目标文件必须存在
    

    仅拷贝状态的信息,包括:mode bits, atime, mtime, flags

    shutil.copystat(src, dst)

    shutil.copystat('f1.log','f2.log')#目标文件必须存在
    

    拷贝文件和权限

    shutil.copy(src, dst)

    import shutil23shutil.copy('f1.log','f2.log')
    

    拷贝文件和状态信息

    shutil.copy2(src, dst)

    import shutil23shutil.copy2('f1.log','f2.log')
    

    递归的去删除文件

    shutil.rmtree(path[, ignore_errors[, onerror]])

    import shutil
    shutil.rmtree('folder1')
    

    递归的去移动文件,它类似mv命令,其实就是重命名。

    shutil.move(src, dst)

    import shutil
    shutil.move('folder1','folder3')
    
  • 相关阅读:
    C#设计模式-单例模式
    MVC图片上传并显示缩略图
    asp.net MVC发布iis无法加载css,js和图片
    Silverlight中获取控件中子控件
    Lambda加自定义比较器实现两个列表的合并
    MVC文件上传
    pt-osc测试
    MySQL DDL方案测试及选型.
    gh-ost测试
    gh-ost原理
  • 原文地址:https://www.cnblogs.com/kai-/p/12591901.html
Copyright © 2011-2022 走看看