On this page
  1. shutil.rmtree
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

shutil.rmtree

Prev: shutil.register_unpack_format | Up: shutil | Next: shutil.SameFileError
Rel: shutil.chown, shutil.copy, shutil.copy2, shutil.copyfile
Ref: docs.python.org — shutil.rmtree
Tags: #public #python3 #stdlib #shutil


Import

import shutil
from shutil import rmtree

Signature & Overview

shutil.rmtree(path, ignore_errors=False, onerror=None, *, onexc=None, dir_fd=None)

Recursively delete a directory tree.

Usage

from pathlib import Path
import shutil
import tempfile

tmp = Path(tempfile.mkdtemp())
(tmp / "nested").mkdir()
(tmp / "nested" / "file.txt").write_text("bye", encoding="utf-8")

shutil.rmtree(tmp)
assert not tmp.exists()

Gotchas

REPL Inspect

from shutil import rmtree
help(rmtree)

Linked from

Related notes