📜  python删除目录即使不为空 - Python代码示例

📅  最后修改于: 2022-03-11 14:45:13.604000             🧑  作者: Mango

代码示例4
# 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))