close

【shutil】Python 檔案移動複製刪除及複製資料夾等等常見操作

 

一、前言


Python 檔案移動、Python檔案複製、

Python檔案刪除、Python複製資料夾等等常見操作。

 

進入基本教學前,不要忘了訂閱按讚分享唷!

部落格教學網站:
https://pixnashpython.pixnet.net/blog
想要即時訂閱最新文章:
https://forms.gle/MdXmiF2HgHhNChL46
訂閱Telegram來接收最新資訊:
https://t.me/joinchat/VUUuDt67Uq5l6CIQ

 

 

二、shutil檔案操作


 

import shutil


# 複製A資料夾內所有資料到B資料夾
A_path = r'./A'
B_path = r'./B'

shutil.copytree(A_path, B_path)


# 刪除資料夾及資料夾內所有資料
shutil.rmtree(A_path)


# 移動文件
shutil.move(A_path, B_path)


# 複製單一文件
fileA_path = 'fileA.txt'
fileB_path = 'fileB.txt'
shutil.copyfile(fileA_path, fileB_path)

 

 

三、後記


用shutil簡單好懂,基本上常用的操作可以直接用成bat這樣工作效率高很多。

 

部落格教學網站:
https://pixnashpython.pixnet.net/blog
想要即時訂閱最新文章:
https://forms.gle/MdXmiF2HgHhNChL46
訂閱Telegram來接收最新資訊:
https://t.me/joinchat/VUUuDt67Uq5l6CIQ

arrow
arrow

    恩哥Python 發表在 痞客邦 留言(0) 人氣()