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

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