Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/env python
- import os
- import sys
- # Windows Empty directory cleaner
- # Drag and drop a root folder on top of this script to remove all empty directories within the hierarchy there below.
- # Also accepts the root level directory as a trailing command line argument.
- confirm = False
- path = r'%s' % sys.argv[ -1 ]
- def rm( folder ):
- """Removes a folder"""
- try:
- os.rmdir( r'%s' % folder )
- print '--[ Deleted %s' % folder
- return True
- except:
- return False
- for folder,subfolder,files in os.walk( path ):
- if ( subfolder == [] and files == [] ):
- if not confirm:
- answer = raw_input( '--[Confirm] Remove: %s ? (yes/no/all)' % folder )
- if answer in ( 'all', 'All', 'ALL', 'a' ):
- confirm = True
- rm( folder )
- elif answer in ( 'yes', 'YES', 'Yes', 'y'):
- rm( folder )
- else:
- continue
- else:
- rm( folder )
- raw_input( '--[Done] Press any key to continue' )
Advertisement
Add Comment
Please, Sign In to add comment