def rm_all_but(base_dir, dirs_to_keep, warn=False):
 try:
  all_dirs = os.listdir(base_dir)
 except OSError:
  u'Dir has been deleted'
  return
 all_dirs = [d for d in all_dirs if (not d.startswith(u'log.'))]
 dirs_to_rm = list(dirs_to_keep.symmetric_difference(all_dirs))
 for dir_name in dirs_to_rm:
  dir_name = os.path.join(base_dir, dir_name)
  if os.path.exists(dir_name):
   if warn:
    print((u'removing directory: %s' % dir_name))
   shutil.rmtree(dir_name)

def rm_all_but ( base_dir , dirs_to_keep , warn = False ) : try : all_dirs = os . listdir ( base_dir ) except OSError : return all_dirs = [ d for d in all_dirs if ( not d . startswith ( u'log.' ) ) ] dirs_to_rm = list ( dirs_to_keep . symmetric_difference ( all_dirs ) ) for dir_name in dirs_to_rm : dir_name = os . path . join ( base_dir , dir_name ) if os . path . exists ( dir_name ) : if warn : print ( ( u'removing directory: %s' % dir_name ) ) shutil . rmtree ( dir_name )
remove all the sub-directories of base_dir .