How do I delete a possibly non-empty dir in Python.
The directory may have nested subdirectories many levels deep.
How do I delete a possibly non-empty dir in Python.
The directory may have nested subdirectories many levels deep.
Use shutil.rmtree
:
shutil.rmtree(path)
See the documentation for details of how to handle and/or ignore errors.
You want shutil.rmtree
shutil.rmtree(path[, ignore_errors[, onerror]])
Delete an entire directory tree; path must point to a directory (but not a symbolic link to a directory). If ignore_errors is true, errors resulting from failed removals will be ignored; if false or omitted, such errors are handled by calling a handler specified by onerror or, if that is omitted, they raise an exception.