Created
February 24, 2018 00:13
-
-
Save anonymous/bdcc59e8b72a7ae60ce5a2340093ca86 to your computer and use it in GitHub Desktop.
This Python script deletes all blank folders under a given path. Minimum python version: 3.5.
This file contains 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
#------------------------------------------------------------- | |
# rmblanks.py | |
# Deletes all empty folders under a given path. | |
# http://metinsaylan.com | |
#------------------------------------------------------------- | |
# Usage: rmblanks.py "E:/Test" | |
import sys, os | |
if len(sys.argv) == 1: | |
# Print usage | |
print("Usage: rmblanks.py \"E:/TestFolder\"") | |
else: | |
for root, dirs, files in os.walk(sys.argv[1], topdown=False): | |
for name in dirs: | |
try: | |
if len(os.listdir( os.path.join(root, name) )) == 0: #check whether the directory is empty | |
print( "Deleting", os.path.join(root, name) ) | |
try: | |
os.rmdir( os.path.join(root, name) ) | |
except: | |
print( "FAILED :", os.path.join(root, name) ) | |
pass | |
except: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment