On this page
os.rmdir
Prev: os.replace | Up: os | Next: os.scandir
Rel: os.abort, os.access, os.chdir, os.chmod
Ref: docs.python.org — os.rmdir
Tags: #public #python3 #stdlib #os
Import
import os
from os import rmdir
Signature & Overview
os.rmdir(path, *, dir_fd=None)
Remove a directory.
Usage
import os
from pathlib import Path
import tempfile
with tempfile.TemporaryDirectory() as tmp:
empty = Path(tmp) / "empty"
empty.mkdir()
os.rmdir(empty)
assert not empty.exists()
Gotchas
- Empty directories only: Raises
OSError(ENOTEMPTY) if the directory contains any files—useshutil.rmtree()for recursive deletion.
REPL Inspect
from os import rmdir
help(rmdir)
Linked from
Related notes
- tuts/python3/stdlib_module/os/replace Linked here; links to this page; shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/scandir Linked here; links to this page; shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/os/abort Linked here; shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/access Linked here; shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/chdir Linked here; shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/chmod Linked here; shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/chown shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/close shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/cpu_count shared tags: #os, #stdlib