Python shutil module

Source: Internet
Author: User

Shutil Module

Introduced: Import Shutil

Copy ()
功能:复制文件格式:shutil.copy(‘来源文件‘,‘目标地址‘)返回值:复制之后的路径
Copy2 ()
功能:复制文件,保留元数据格式:shutil.copy2(‘来源文件‘,‘目标地址‘)返回值:复制之后的路径
Copyfileobj ()
将一个文件的内容拷贝的另外一个文件当中格式:shutil.copyfileobj(open(来源文件,‘r‘),open(‘目标文件‘,‘w‘))返回值:无
CopyFile ()
功能:将一个文件的内容拷贝的另外一个文件当中格式:shutil.copyfile(来源文件,目标文件)返回值:目标文件的路径
Copytree ()
功能:复制整个文件目录格式:shutil.copytree(来源目录,目标目录)返回值:目标目录的路径注意:无论文件夹是否为空,均可以复制,而且会复制文件夹中的所有内容
Copymode ()
功能:拷贝权限
Copystat ()
功能:拷贝元数据(状态)
Rmtree ()
功能:移除整个目录,无论是否空格式:shutil.rmtree(目录路径)返回值:无
Move ()
功能:移动文件或者文件夹格式:shutil.move(来源地址,目标地址)返回值:目标地址
Which ()
功能:检测命令对应的文件路径格式:shutil.which(‘命令字符串’)返回值:命令文件所在位置注意:window和linux不太一样。 window的命令都是.exe结尾,linux则不是
Disk_usage ()
功能:检测磁盘使用信息格式:disk_usage(‘盘符’)返回值:元组
Archive and package operations

Archive: Merging multiple files into a single file, this is done by filing.

Unpacking: releasing archived files.

Compression: Multiple files are combined in a file with lossy or lossless compression.

Decompression: Is the compression of the reverse operation, will be compressed files in the file, released.

Note: compression belongs to archive!
Make_archive ()
功能:归档函数,归档操作格式:shutil.make_archive(‘目标文件路径‘,‘归档文件后缀‘,‘需要归档的目录‘)返回值:归档文件的最终路径
Unpack_archive ()
功能:解包操作格式:shutil.unpack_archive(‘归档文件路径‘,‘解包目标文件夹‘)返回值:None注意:文件夹不存在会新建文件夹
Get_archive_formats ()
功能:获取当前系统已注册的归档文件格式(后缀)格式:shutil.get_archive_formats()返回值:列表   [(后缀,解释),(后缀,解释),(后缀,解释)...]
Get_unpack_formats ()
功能:获取当前系统已经注册的解包文件格式(后缀)格式:shutil.get_unpack_formats()返回值:列表   [(后缀,解释),(后缀,解释),(后缀,解释)...]

Python shutil module

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.