Date Tags Python

Late one night I needed to write some Python code to recursively find empty directories. Searching online produced some unsatisfactory solutions. Here is a simple solution that leverages os.walk.

import os

empty_dirs = []
for root, dirs, files in os.walk(starting_path):
   if not len(dirs) and not len(files):

If you then wish to delete these empty directories:

for path in empty_dirs:


comments powered by Disqus