shutil 模块,高级文件操作模块,支持文件或文件夹的复制和删除

模块方法:

shutil.copyfileobj(fsrc, fdst[, length]):将类文件对象(在python中打开的文件)fsrc 的内容,拷贝到类文件对象 fdst 中,length 指定每次拷贝缓存大小
shutil.copyfile(src, dst):将文件 src 的内容拷贝到 dst 中,dst 如果是已经存在的文件,就会重写,如果 src 和 dst 是同一个文件会报错
shutil.copymode(src,dst):仅拷贝权限,不更改文件内容,组和用户,dst 一定是一个已经存在的文件
shutil.copystat(src,dst):拷贝所有的状态信息,包括权限,组,用户,时间等,是 copymode 的拓展
shutil.copy(src,dst):拷贝文件的内容以及权限,先 copyfile 后 copymode
shutil.copy2(src,dst):拷贝文件的内容以及文件的所有状态信息。先 copyfile 后 copystat
shutil.copytree(src, dst, symlinks=False, ignore=None):把 src 下所有文件及文件夹递归复制到 dst 中,dst 一定是不能之前存在的,symlinks 指定是否以符号链接形式拷贝,ignore 设置忽略的文件,需要一个可调用对象,可以由 ignore_patterns 获得
shutil.ignore_patterns(*patterns):用于 copytree
shutil.rmtree(path, ignore_errors=False, onerror=None):递归删除 path 下所有文件
shutil.move(src, dst):递归移动 src 文件或文件夹至 dst 中
shutil.make_archive(base_name, format[, root_dir[, base_dir[, verbose[, dry_run[, owner[, group[, logger]]]]]]]):压缩打包一个文件或文件夹,base_name 设置压缩打包后的文件名或者路径名,format 设置压缩或者打包格式,"zip", "tar", "bztar","gztar",root_dir 设置将哪个目录或者文件打包(也就是源文件)
shutil.get_archive_formats():返回支持压缩的格式列表
shutil.register_archive_format(name, function[, extra_args[, description]]):添加一个压缩方法
shutil.unregister_archive_format(name):移除一个压缩方法

Python2.7-shutil的更多相关文章

  1. Python之路【第二十三篇】爬虫

    difference between urllib and urllib2 自己翻译的装逼必备 What is the difference between urllib and urllib2 mo ...

  2. macosx 10.11 python pip install 出现错误OSError: [Errno 1] Operation not permitted:

    Exception: Traceback (most recent call last): File , in main status = self.run(options, args) File , ...

  3. mac安装Aws cli失败

    OS X EI 10.11 报错信息如下: Found existing installation: six 1.4.1 DEPRECATION: Uninstalling a distutils i ...

  4. MAC 下安装PIL

    1. 安装使用 pip install pil 结果报如下错误 Collecting PIL Could not find a version that satisfies the requireme ...

  5. Summary on deep learning framework --- PyTorch

    Summary on deep learning framework --- PyTorch  Updated on 2018-07-22 21:25:42  import osos.environ[ ...

  6. 错误:OSError: [Errno 1] Operation not permitted: 'lib/python/six-1.4.1-py2.7.egg-info'

    解决办法: $ $ pip install mock --ignore-installed six --user 问题:安装mock时报错: (venv)➜ test git:(master) pip ...

  7. 安装 tensorflow 时遇到 OSError: [Errno 1] Operation not permitted 的解决办法

    Installing collected packages: numpy, scipy, six, pyyaml, Keras, opencv-python, h5py, html5lib, blea ...

  8. mac 下 python 虚拟环境的安装和配置

    前言:继续安装中,这节记录 mac 安装 python 虚拟环境,多版本共存... 1. 安装 pip -- python的包管理工具: sudo easy_install pip 安装成功,出现下面 ...

  9. mac安装jupyter

    SaintKings-Mac-mini:.pip saintking$ pip install jupyter --user Collecting jupyter Downloading jupyte ...

  10. Python之文件与目录操作及压缩模块(os、shutil、zipfile、tarfile)

    Python中可以用于对文件和目录进行操作的内置模块包括: 模块/函数名称 功能描述 open()函数 文件读取或写入 os.path模块 文件路径操作 os模块 文件和目录简单操作 zipfile模 ...

随机推荐

  1. Java - TreeMap源码解析 + 红黑树

    Java提高篇(二七)-----TreeMap TreeMap的实现是红黑树算法的实现,所以要了解TreeMap就必须对红黑树有一定的了解,其实这篇博文的名字叫做:根据红黑树的算法来分析TreeMap ...

  2. 生成证书申请csr文件

    一.执行命令 openssl req -nodes -newkey rsa:2048 -keyout liexiulive.key -out liexiulive.csr 二.根据提示输入基本信息 G ...

  3. Codeforces731C(SummerTrainingDay06-M 并查集)

    C. Socks time limit per test:2 seconds memory limit per test:256 megabytes input:standard input outp ...

  4. JavaScript--DOM进阶(20)

    // DOM自身存在很多类型,在上一章中有介绍,比如Element类型:表示的是元素节点;再比如Text类型;表示的是文本节点; 一 DOM类型 类型名 说明 Node 表示所有类型值的统一接口,IE ...

  5. flex 总结

  6. 学习笔记(2)——实验室集群LVS配置

    查看管理结点mgt的网卡信息,为mgt设置VIP [root@mgt ~]# ifconfig eth0 Link encap:Ethernet HWaddr 5C:F3:FC:E9:: inet a ...

  7. android开发之braodCast

    广播问题: 遇到了broadcast中sendBroadcast之后,注册registerReceiver的receiver接受不到广播,原因是permisson权限问题. 自定义的permissio ...

  8. GDI+编程(画笔/画刷/路径/区域)

    构造Graphics对象 Graphics类是GDI+程序设计的核心,Graphics类能够完成大部分的绘图,文本输出,几何图形的填充及坐标系统的转换等各种操作.在功能上,它与GDI的设备环境(DC) ...

  9. oracle学习之pl/sql使用==转载

    PLSQL循序渐进全面学习教程(全):https://blog.csdn.net/spark998/article/details/2065269

  10. LintCode题解之Search Range in Binary Search Tree

    1.题目描述 2.问题分析 首先将二叉查找树使用中序遍历的方式将元素放入一个vector,然后在vector 中截取符合条件的数字. 3.代码 /** * Definition of TreeNode ...