FINDING EMPTY DIRECTORIES
Python
#!/usr/bin/env python3
"""FINDING EMPTY DIRECTORIES"""
import os, tempfile
temp = tempfile.gettempdir()
test_dir = os.path.join(temp, "empty_test")
os.makedirs(os.path.join(test_dir, "empty1"))
os.makedirs(os.path.join(test_dir, "empty2"))
os.makedirs(os.path.join(test_dir, "not_empty"))
open(os.path.join(test_dir, "not_empty/file.txt"), 'w').write("test")
empty_dirs = []
for root, dirs, files in os.walk(test_dir):
if not dirs and not files:
empty_dirs.append(os.path.relpath(root, test_dir))
print(f"Empty directories: {empty_dirs}")
import shutil
shutil.rmtree(test_dir)