all Python 3osfunction
os.rmdir
os — directories
Remove an empty directory; a non-empty one raises OSError — shutil.rmtree removes a tree.
Syntax
os.rmdir(path)
It removes only an empty directory: anything inside gives OSError. A whole tree needs shutil.rmtree — and that deserves more caution than rmdir, since it deletes without asking. On Windows a directory that is another process's current directory cannot be removed.
Examples
import os
os.mkdir('empty_dir')
os.rmdir('empty_dir')
print(os.path.exists('empty_dir')) # → False
os.makedirs('a/b/c', exist_ok=True)
os.rmdir('a/b/c') # → удаляет только пустую c
print(os.path.isdir('a/b')) # → True
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy