码迷,mamicode.com
首页 > 编程语言 > 详细

python之shutil

时间:2019-04-28 22:05:16      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:bsp   port   txt   递归   删除   ret   python   obj   拷贝文件   

 

‘‘‘
shutil
用来处理 文件 文件夹 压缩包 的模块
‘‘‘

import shutil

# 拷贝文件内容
shutil.copyfileobj(open(old.xml, r), open(new.xml, w))

# 拷贝文件
shutil.copyfile(f1.log, f2.log)

# 拷贝权限
shutil.copymode(f1.log, f2.log)

# 拷贝文件状态信息
shutil.copystat(f1.log, f2.log)

# 拷贝文件和权限
shutil.copy(f1.log, f2.log)

# 递归地拷贝文件夹
# shutil.copytree(folder1, folder2,
ignore=shutil.ignore_patterns(*.pyc, *.txt))

# 递归地删除文件
# shutil.rmtree(folder2)

# 递归地移动重命名文件
# shutil.move(folder2, folder3)

# 打包文件
ret = shutil.make_archive(rC:\GitHub\Python\day7\shutil\www, gztar,
root_dir=rC:\GitHub\Python\day7\shutil\folder1)

 

python之shutil

标签:bsp   port   txt   递归   删除   ret   python   obj   拷贝文件   

原文地址:https://www.cnblogs.com/wanghuixi/p/10787123.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!