rmEmptyDirs.py

#!/usr/bin/env python

"""
$Id: rmEmptyDirs.py 273 2001-11-05 13:19:48Z david $

Simply removes all empty subdirectories of a given directory.  Useful for
cleaning up after a rogue script.  Not that I've had that happen to me or
anything...
"""

import sys, os


def removeDirectoryIfEmpty (arg, directory, subs):
	if not subs:
		os.rmdir(directory)


try:
	directory = sys.argv[1]
except IndexError:
	sys.stderr.write("Usage: %s <dir>\n" % os.path.basename(sys.argv[0]))
	sys.exit(1)
os.path.walk(directory, removeDirectoryIfEmpty, None)