Created
November 15, 2012 15:43
-
-
Save noxan/4079263 to your computer and use it in GitHub Desktop.
remove empty folders
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 removeEmptyFolders(path): | |
if not os.path.isdir(path): | |
return | |
# walk through folders | |
files = os.listdir(path) | |
if len(files): | |
for f in files: | |
fullpath = os.path.join(path, f) | |
if os.path.isdir(fullpath): | |
removeEmptyFolders(fullpath) | |
# delete empty folders | |
if len(files) == 0: | |
print "Remove empty folder: ", path | |
os.rmdir(path) | |
if __name__ == "__main__": | |
removeEmptyFolders('/home/noxan/Music/') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment