Skip to content

Instantly share code, notes, and snippets.

@jreisinger
Created February 12, 2018 12:05
Show Gist options
  • Select an option

  • Save jreisinger/082047914c3c4ac68246bea3e75b3c42 to your computer and use it in GitHub Desktop.

Select an option

Save jreisinger/082047914c3c4ac68246bea3e75b3c42 to your computer and use it in GitHub Desktop.
#!/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