下面來看一下python裡面是如何刪除一個文件及文件夾的~~
首先引入OS模塊
import os
刪除文件:
os.remove()
刪除空目錄:
os.rmdir( )
遞歸刪除空白目錄:
os.removedirs()
遞歸刪除目錄和檔案(類似DOS指令DeleteTree):
方法1:
# Delete everything reachable from directory named there are no symbolic links.
# CAUTION: This is dangerous! For example, if top == '/', it
# could delete all your disk files.
import os
os
, in os
, os
os
, os
, os
. top, topdown=False):
for name in files:
os.remove(os.path.join(root, name))
方法2:利用python的成熟的模組
shutil.rmtree()