目錄
基礎(chǔ)部分
shutil.copyfileobj(file1,file2):
shutil.copyfile(file1,file2):
其他
shutil.copymode(file1,file2):
shutil.copystat(file1,file2):
shutil.copy(file1,file2):
shutil.copy2(file1,file2):
shutil.copytree(源目錄,目標(biāo)目錄):
shutil.rmtree(目標(biāo)目錄):
shutil.move(源文件,指定路徑):
shutil.make_archive():
shutil.make_archive(base_name, format,...)
基礎(chǔ)部分
shutil.copyfileobj (file1,file2):
將文件1的數(shù)據(jù)覆蓋copy給文件2。
import shutil
f1 = open("1.txt",encoding="utf-8")
f2 = open("2.txt","w",encoding="utf-8")
shutil.copyfileobj(f1,f2)
運(yùn)行前:
運(yùn)行后:
shutil.copyfile(file1,file2):
不用打開文件,直接用文件名進(jìn)行覆蓋copy。
import shutil
shutil.copyfile("1.txt","3.txt")
其他
shutil.copymode(file1,file2):
只拷貝權(quán)限,內(nèi)容組,用戶,均不變。
shutil.copystat(file1,file2):
只拷貝了權(quán)限。
shutil.copy(file1,file2):
拷貝文件和權(quán)限都進(jìn)行copy。
shutil.copy2(file1,file2):
拷貝了文件和狀態(tài)信息。
shutil.copytree(源目錄,目標(biāo)目錄):
可以遞歸copy多個(gè)目錄到指定目錄下。
shutil.rmtree(目標(biāo)目錄):
可以遞歸刪除目錄下的目錄及文件。
shutil.move(源文件,指定路徑):
遞歸移動(dòng)一個(gè)文件。
shutil.make_archive():
可以壓縮,打包文件。
shutil.make_archive(base_name, format,...)
創(chuàng)建壓縮包并返回文件路徑,例如:zip、tar
- base_name: 壓縮包的文件名,也可以是壓縮包的路徑。只是文件名時(shí),則保存至當(dāng)前目錄,否則保存至指定路徑,
-
如:www ? ? ? ? ? ? ? ? ? ? ? ?=>保存至當(dāng)前路徑
如:/Users/wupeiqi/www =>保存至/Users/wupeiqi/ - format: 壓縮包種類,“zip”, “tar”, “bztar”,“gztar”
- root_dir: 要壓縮的文件夾路徑(默認(rèn)當(dāng)前目錄)
- owner: 用戶,默認(rèn)當(dāng)前用戶
- group: 組,默認(rèn)當(dāng)前組
- logger: 用于記錄日志,通常是logging.Logger對(duì)象
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號(hào)聯(lián)系: 360901061
您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對(duì)您有幫助就好】元
