学习Python的标准库 shutil的拷贝函数

shutil模块

copy函数

copy(src, dst, *, follow_symlinks=True)
    Copy data and mode bits ("cp src dst"). Return the file's destination.
    
    The destination may be a directory.
    
    If follow_symlinks is false, symlinks won't be followed. This
    resembles GNU's "cp -P src dst".
    
    If source and destination are the same file, a SameFileError will be
    raised.

拷贝一个文件或目录到另一个文件 和权限 如果src 和dst相同,则会抛出异常SameFileError。

返回值是目标文件

copy2函数

copy2(src, dst, *, follow_symlinks=True)
    Copy data and all stat info ("cp -p src dst"). Return the file's
    destination."
    
    The destination may be a directory.
    
    If follow_symlinks is false, symlinks won't be followed. This
    resembles GNU's "cp -P src dst".

在copy的基础上,复制文件的访问时间和修改时间,及文件的状态

copyfile函数

copyfile(src, dst, *, follow_symlinks=True)
    Copy data from src to dst.
    
    If follow_symlinks is not set and src is a symbolic link, a new
    symlink will be created instead of copying the file it points to.

拷贝文件

copyfileobj函数

功能于copy file函数类似

copymode函数

复制文件的权限

copymode(src, dst, *, follow_symlinks=True)
    Copy mode bits from src to dst.
    
    If follow_symlinks is not set, symlinks aren't followed if and only
    if both `src` and `dst` are symlinks.  If `lchmod` isn't available
    (e.g. Linux) this method does nothing.

copystart函数

拷贝文件的状态信息

copytree函数

递归的拷贝文件

remstree函数

递归删除文件

move函数

递归的移动文件

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值