Created
January 6, 2012 05:31
-
-
Save kylexlau/1569173 to your computer and use it in GitHub Desktop.
Python delete empty directories, recursive algorithm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
def del_empty_dirs(s_dir,f): | |
b_empty = True | |
for s_target in os.listdir(s_dir): | |
s_path = os.path.join(s_dir, s_target) | |
if os.path.isdir(s_path): | |
if not del_empty_dirs(s_path): | |
b_empty = False | |
else: | |
b_empty = False | |
if b_empty: | |
print('del: %s' % s_dir) | |
os.rmdir(s_dir) | |
return b_empty |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks nice! but what is "f" parameter in line 3 ?