shutil模块,ZipFile 和 TarFile 两个模块
高级的文件、文件夹、压缩包处理模块
shutil.copyfileobj(fsrc, fdst[, length])
将文件内容拷贝到另一个文件中,可以部分内容
shutil.copyfile(src, dst)
拷贝文件
shutil.copymode(src, dst)
仅拷贝权限。内容、组、用户均不变,
shutil.copystat(src, dst)
拷贝状态的信息,包括:mode bits, atime, mtime, flags
只拷贝修改时间和访问时间,其他不拷贝,包括权限和创建时间
shutil.copy(src, dst)
拷贝文件和权限
shutil.copy2(src, dst)
拷贝文件和状态信息
shutil.ignore_patterns(*patterns)
shutil.copytree(src, dst, symlinks=False, ignore=None)
递归的去拷贝文件,这里test4,new_test4的源目标都是目录
例如:copytree(source, destination, ignore=ignore_patterns('*.pyc', 'tmp*'))
shutil.rmtree(path[, ignore_errors[, onerror]])
递归的去删除文件和目录
shutil.move(src, dst)
递归的去移动文件
shutil.make_archive(base_name, format,...)
创建压缩包并返回文件路径,例如:zip、tar
base_name: 压缩包的文件名,也可以是压缩包的路径。只是文件名时,则保存至当前目录,否则保存至指定路径,
如:www =>保存至当前路径
如:/Users/wupeiqi/www =>保存至/Users/wupeiqi/
format: 压缩包种类,“zip”, “tar”, “bztar”,“gztar”
root_dir: 要压缩的文件夹路径(默认当前目录)
owner: 用户,默认当前用户
group: 组,默认当前组
logger: 用于记录日志,通常是logging.Logger对象
shutil 对压缩包的处理是调用 ZipFile 和 TarFile 两个模块来进行的,详细:
shutil.make_archive是对文件夹进行压缩,ZipFile是对文件进行压缩
shutil模块,ZipFile 和 TarFile 两个模块的更多相关文章
- shutil,zipfile,tarfile模块
一,shutil模块 1.shutil.chown() shutil.chown('test.txt',user='mysql',group='mysql') #改变文件的属主和属组. 2.shuti ...
- s14 第5天 时间模块 随机模块 String模块 shutil模块(文件操作) 文件压缩(zipfile和tarfile)shelve模块 XML模块 ConfigParser配置文件操作模块 hashlib散列模块 Subprocess模块(调用shell) logging模块 正则表达式模块 r字符串和转译
时间模块 time datatime time.clock(2.7) time.process_time(3.3) 测量处理器运算时间,不包括sleep时间 time.altzone 返回与UTC时间 ...
- Python之文件与目录操作及压缩模块(os、shutil、zipfile、tarfile)
Python中可以用于对文件和目录进行操作的内置模块包括: 模块/函数名称 功能描述 open()函数 文件读取或写入 os.path模块 文件路径操作 os模块 文件和目录简单操作 zipfile模 ...
- python笔记07-----打包模块(shutil,zipfile,tarfile)
1.shutil模块 复制删除 import shutil shutil.copy('filename', 'test2') # copy方法 f1 = open('filename',encodin ...
- python常用标准库(压缩包模块zipfile和tarfile)
常用的标准库 在我们常用的系统windows和Linux系统中有很多支持的压缩包格式,包括但不限于以下种类:rar.zip.tar,以下的标准库的作用就是用于压缩解压缩其中一些格式的压缩包. zip格 ...
- Python 基础之压缩模块zipfile与tarfile
一.压缩模块 zipfile (1)创建一个zip压缩包 import zipfile #zip_deflated 代表是压缩的意思#打开压缩包zf = zipfile.ZipFile("c ...
- shutil、zipfile,tarfile
shutil 模块提供了大量的文件的高级操作.特别针对文件拷贝和删除,主要功能为目录和文件操作以及压缩操作. 1. shutil.copyfileobj(fsrc, fdst[, length]) 功 ...
- 模块-os.system的两个模块/random模块/datetime模块/写日志
一.获取当前目录的路径 os.path.abspath('.')# 取绝对路径 os.getcwd()# 取当前路径 .代表当前目录 ..上一级目录 ../.. 二.执行操作系统命令1.os.syst ...
- Python中模块之shutil及zipfile&tarfile的功能介绍
shutil的功能介绍及其他打包.压缩模块 1. shutil模块的方法 chown 更改指定路径的属组 2. copy 拷贝文件和权限 方法:shutil.copy(src,dst,*,follow ...
随机推荐
- python学习笔记(virtualenv下载安装)
之前博客评论中有人建议我面对多个python版本的情况.可以使用virtualenv这个python虚拟沙盒 首页是利用pip下载.关于pip如何下载安装前面的博客中已经提到就不细说 cmd直接进入p ...
- WPF中关于配置文件的读取
在WPF中的配置文件的读取也是经常用到的一个操作,虽然很基础,但是也记录一下,以后忘记了可以看一看. 首先就是先新建一个Application Configuration Flie后缀名是.confi ...
- Android GridView 行间距过大(一页一行)
1. gridView.xml中 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android&quo ...
- nyoj-5-kmp裸题
题目链接: http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=5 kmp统计匹配串出现次数,贼尴尬好久没做字符串题目,一开始求得是文本串的next ...
- TCP/UDP编程步骤和区别
一. 概念解析 套接字:一种特殊的文件描述符.一头指向套接字地址(用户),一头指向套接字结构(内核). 套接字结构:由内核维持的一种数据结构,可通过套接字来操作. 套接字地址:ip和port. 二. ...
- python练习题100例
链接地址:http://www.runoob.com/python/python-100-examples.html
- jQueryValidation插件API 学习
一般格式: $('').viladata({ rules:{ username:{ required:true, maxlength:2, minlength:10, remote:{ url:&qu ...
- LeetCode OJ:Roman to Integer(转换罗马字符到整数)
Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 t ...
- react-redux: async promise
1.the simple sample action: 事实上,只是返回个一个至少包含type的对象{ },用于reducer接收. import {RECEIVE_DATA} from " ...
- win7 秘钥
链接 安装好Windows7后右击计算机--属性--更改产品密匙 输入以下密匙; RHTBY-VWY6D-QJRJ9-JGQ3X-Q2289 HT6VR-XMPDJ-2VBFV-R9PFY-3VP7R ...