Ric*_*dle 90
import shutil
shutil.rmtree(path)
Run Code Online (Sandbox Code Playgroud)
有关如何处理和/或忽略错误的详细信息,请参阅文档.
dgh*_*dgh 60
标准库包含shutil.rmtree.默认情况下,
shutil.rmtree(path) # errors if dir not empty
Run Code Online (Sandbox Code Playgroud)
会给OSError: [Errno 66] Directory not empty: <your/path>.
您可以通过忽略错误来删除目录及其内容:
shutil.rmtree(role_fs_path, ignore_errors=True)
Run Code Online (Sandbox Code Playgroud)
您也可以通过传递来执行更复杂的错误处理onerrror=<some function(function, path, excinfo)>.
And*_*lke 10
shutil.rmtree(path [,ignore_errors [,onerror]])
删除整个目录树; path必须指向目录(但不是指向目录的符号链接).如果ignore_errors为true,则将忽略由删除失败导致的错误; 如果为false或省略,则通过调用onerror指定的处理程序来处理此类错误,或者,如果省略,则会引发异常.
| 归档时间: |
|
| 查看次数: |
58611 次 |
| 最近记录: |