美文网首页
Python shutil库

Python shutil库

作者: Mrmcling | 来源:发表于2020-07-29 17:38 被阅读0次

    1.shutil.rmtree('test') 删除目录(删除文件使用os包的remove)
    2.shutil.move('test.txt', 'tmp.txt') 重命名文件及文件夹
    3.shutil.make_archive('test', 'zip', 'test') 压缩文件(# "zip", "tar", "gztar","bztar", or "xztar")
    4.shutil.unpack_archive('test.zip', extract_dir='D:\newdir', format='zip') 解压(指定目录如果没有,自动创建)
    5.shutil.copyfileobj(open('test.txt', 'r'), open('log.txt', 'w')) 将一个文件内容拷贝到另一个文件中(目标文件如果不存在,自动创建)
    6.shutil.copyfile('test.txt','log.txt')

    相关文章

      网友评论

          本文标题:Python shutil库

          本文链接:https://www.haomeiwen.com/subject/nghkrktx.html