python教程八(shutil模組)

2021-10-12 16:33:26 字數 527 閱讀 8834

#shutil可以實現檔案的複製,移動

import shutil

複製檔案:

shutil.copyfile(

"oldfile"

,"newfile"

)# oldfile和newfile都只能是檔案

shutil.copy(

"oldfile"

,"newfile"

)# oldfile只能是檔案,newfile可以是檔案,也可以是目標目錄

複製資料夾:

shutil.copytree(

"olddir"

,"newdir"

)# olddir和newdir都只能是目錄,且newdir必須不存在

移動檔案/目錄

shutil.move(

"older, "newer")

shutil.move(

"d:/files/100.pdf"

,"d:/files2/"

)'''

Python擴充套件包之shutil

os模組 提供了對目錄或者檔案的新建 刪除 檢視檔案屬性,還提供了對檔案以及目錄的路徑操作。比如說 絕對路徑,父目錄 但是,os檔案的操作還應該包含 移動 複製 打包 壓縮 解壓 等操作,這些os模組都沒有提供。shutil提供了 移動 複製 打包 壓縮 解壓等功能。1 shutil.copyfil...

python模組之shutil模組

高階的 檔案 資料夾 壓縮包 處理模組 shutil.copyfileobj fsrc,fdst length 將檔案內容拷貝到另乙個檔案中 import shutil shutil.copyfileobj open old.xml r open new.xml w shutil.copyfile ...

Python 標準庫之 shutil

shutil是shell utilities的簡寫,它提供了大量的檔案和目錄的高階操作。特別針對檔案 目錄的拷貝和刪除,主要功能為目錄和檔案操作以及壓縮操作。函式說明 shutil.copyfile src,dst 從源src複製到dst中去。如果當前的dst已存在的話就會被覆蓋掉,src 和 ds...