def remove_empty_directories(path, remove_root=False, recursive=True):
    "Remove all empty directories while respecting the flags."
    if recursive:
        for name in os.listdir(path):
            try:
                remove_empty_directories(os.path.join(path, name), True)
            except OSError:
                pass
    if remove_root:
        os.rmdir(path)
Remove all empty directories while respecting the flags.
recipes/Python/577633_Directory_Pruner_2/recipe-577633.py