# Delete everything reachable from the directory named in 'top',
# assuming there are no symbolic links.
# CAUTION: This is dangerous! For example, if top == '/', it
# could delete all your disk files.
import os
for root, dirs, files in os.walk(top, topdown=False):
for name in files:
os.remove(os.path.join(root, name))
for name in dirs:
os.rmdir(os.path.join(root, name))
从the python docs到
os.walk()
:Standard Library Reference: shutil.rmtree。
根据设计,
rmtree
在包含只读文件的文件夹树上失败。如果要删除文件夹,而不管它是否包含只读文件,请使用相关问题 更多 >
编程相关推荐