欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

詳解Python_shutil模塊

 更新時間:2019年03月15日 14:04:27   作者:Vera_y  
這篇文章主要介紹了Python_shutil模塊功能,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

import shutil

高級的文件,文件夾,壓縮包的處理模塊,也主要用于文件的拷貝

shutil.copyfileobj(fsrc,fdst[,length]):  將文件的內(nèi)容拷貝到另一個文件(可以指定length長度進(jìn)行拷貝)

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):  僅拷貝權(quán)限,內(nèi)容、組、用戶均不變

import shutil
shutil.copymode('f1.log', 'f2.log')

shutil.copystat(src,dst):  拷貝狀態(tài)的信息,包括:mode bits,atime,mtime,flags

import shutil
shutil.copystat('f1.log', 'f2.log')

shutil.copy(src,dst):  拷貝文件和權(quán)限

import shutil
shutil.copy('f1.log', 'f2.log')

shutil.copy2(src,dst):  拷貝文件和狀態(tài)信息

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,...):  創(chuàng)建壓縮包并返回文件路徑,例如:zip、tar

base_name: 壓縮包的文件名,也可以是壓縮包的路徑。只是文件名時,則保存至當(dāng)前目錄,否則保存至指定路徑(例:Presley=>保存至當(dāng)前路徑,/User/Presley =>保存至/Users/路徑下)
format: 壓縮包種類,“zip”, “tar”, “bztar”,“gztar”
root_dir: 要壓縮的文件夾路徑(默認(rèn)當(dāng)前目錄)
owner: 用戶,默認(rèn)當(dāng)前用戶
group: 組,默認(rèn)當(dāng)前組

import shutil
z = shutil.make_archive('presly', 'gztar', root_dir='D:\軟件下載')

shutil對壓縮包的處理,也可調(diào)用zipfile或tarfile模塊進(jìn)行壓縮

以上所述是小編給大家介紹的Python_shutil模塊詳解整合,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評論