Created
February 12, 2018 12:05
-
-
Save jreisinger/082047914c3c4ac68246bea3e75b3c42 to your computer and use it in GitHub Desktop.
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
| #!/usr/bin/python3 | |
| import os, shutil, sys | |
| topdir = "" | |
| if len(sys.argv) > 1: | |
| topdir = sys.argv[1] | |
| else: | |
| print("Usage:", sys.argv[0], "DIR") | |
| def yes_or_no(question): | |
| reply = str(input(question+' (y/n): ')).lower().strip() | |
| if reply[0] == 'y': | |
| return True | |
| if reply[0] == 'n': | |
| return False | |
| else: | |
| return yes_or_no("Uhhhh... please enter ") | |
| for dirpath, dirnames, filenames in os.walk(topdir): | |
| if not dirnames: # end-leafe dir | |
| if len(filenames) < 5: | |
| print("\n'{}' looks pretty empty".format(dirpath)) | |
| for file in filenames: | |
| print("-->", file) | |
| if yes_or_no("remove dir?"): | |
| print("removing", dirpath) | |
| shutil.rmtree(dirpath) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment