Python Practice › OS Module Programs › Program 8
Remove an empty folder
Write a Python program to remove an empty directory with os.rmdir().
Output
False
Approach
rmdironly removes empty folders.
Solution
import os os.makedirs("empty_dir", exist_ok=True)os.rmdir("empty_dir")print(os.path.exists("empty_dir"))Output
False
Learn the concept
New to this topic? Read the lesson, then come back.