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')
    
  • 相关阅读:
    Kubernetes List-Watch
    Go 模板语法
    vRA7 Business error “Untrusted certificate chain”
    Centos 7/8 安装 Harbor
    Kubernetes Headless Service
    Kubernetes addon-manager
    Kubernetes Metrics-Server
    Kubernetes Heapster
    容器rootfs
    Kubernetes lxcfs
  • 原文地址:https://www.cnblogs.com/kai-/p/12591901.html
Copyright © 2011-2022 走看看