import shutil
高级的文件,文件夹,压缩包的处理模块,也主要用于文件的拷贝
shutil.copyfileobj(fsrc,fdst[,length]):
将文件的内容拷贝到另一个文件(可以指定length长度进行拷贝)
import shutil shutil.copyfileobj(open('old.txt','r'),open('new.txt','w'))
shutil.copyfile(src,dst):
拷贝文件
import shutil shutil.copyfile('f1.log','f2.log')
shutil.copymode(src,dst):
仅拷贝权限,内容、组、用户均不变
import shutil shutil.copymode('f1.log', 'f2.log')
shutil.copystat(src,dst):
拷贝状态的信息,包括:mode bits,atime,mtime,flags
import shutil shutil.copystat('f1.log', 'f2.log')
shutil.copy(src,dst):
拷贝文件和权限
import shutil shutil.copy('f1.log', 'f2.log')
shutil.copy2(src,dst):
拷贝文件和状态信息
import shutil shutil.copy2('f1.log', 'f2.log')
shutil.copytree(src,det,symlinks=False,ignore=None):
递归的去拷贝文件
import shutil shutil.copytree('folder1', 'folder2', ignore=shutil.ignore_patterns('*.pyc', 'tmp*'))
shutil.rmtree(path[,ignore_errors[,onerror]]):
递归的去删除文件
import shutil shutil.rmtree('folder1')
shutil.move(src,dst):
递归的去移动文件(重命名)
import shutil shutil.move('folder1', 'folder3')
shutil.make_archive(base_name, format,...): 创建压缩包并返回文件路径,例如:zip、tar
base_name: 压缩包的文件名,也可以是压缩包的路径。只是文件名时,则保存至当前目录,否则保存至指定路径(例:Presley=>保存至当前路径,/User/Presley =>保存至/Users/路径下)
format: 压缩包种类,“zip”, “tar”, “bztar”,“gztar”
root_dir: 要压缩的文件夹路径(默认当前目录)
owner: 用户,默认当前用户
group: 组,默认当前组
import shutil z = shutil.make_archive('presly', 'gztar', root_dir='D:\软件下载')
shutil对压缩包的处理,也可调用zipfile或tarfile模块进行压缩
以上所述是小编给大家介绍的Python_shutil模块详解整合,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
更新日志
- 班得瑞原装进口《第五张新世纪专辑:迷雾森林+EP》1CD[APE/CUE分轨][334.2MB]
- 田震.1997-顺其自然(日版)【红星生产社】【WAV+CUE】
- 小虫.1996-想得太美【滚石】【WAV+CUE】
- 谢采妘.2016-邓丽君名曲专辑【丰荣】【WAV+CUE】
- 张含韵.2007-一人一梦【天中文化】【WAV+CUE】
- 蟑螂乐队.1999-帮个忙【福茂】【WAV+CUE】
- 张宇.2001-替身【EMI百代】【WAV+CUE】
- 班得瑞原装进口《第六张新世纪专辑:日光海岸》1CD[APE/CUE分轨][339.5MB]
- 班得瑞原装进口《第七张新世纪专辑:梦花园》1CD[APE/CUE分轨][331.4MB]
- 班得瑞原装进口《第八张新世纪专辑:琉璃湖畔》1CD[APE/CUE分轨][286.4MB]
- 魏如萱.2011-在哪里(EP)【添翼创越】【WAV+CUE】
- 群星.1981-新金曲奖·青年创作园地12合辑(喜玛拉雅复刻版)【歌林】【WAV+CUE】
- 麦洁文.1989-新曲与精丫新艺宝】【WAV+CUE】
- SNH48《薄荷糖 (Mint Candy)》[320K/MP3][33.72MB]
- SNH48《薄荷糖 (Mint Candy)》[FLAC/分轨][78.59MB]