def prune_dirs(path, root=None, clutter=('.DS_Store', 'Thumbs.db')):
 path = normpath(path)
 if (root is not None):
  root = normpath(root)
 ancestors = ancestry(path)
 if (root is None):
  ancestors = []
 elif (root in ancestors):
  ancestors = ancestors[(ancestors.index(root) + 1):]
 else:
  return
 ancestors.append(path)
 ancestors.reverse()
 for directory in ancestors:
  directory = syspath(directory)
  if (not os.path.exists(directory)):
   continue
  clutter = [bytestring_path(c) for c in clutter]
  match_paths = [bytestring_path(d) for d in os.listdir(directory)]
  if fnmatch_all(match_paths, clutter):
   try:
    shutil.rmtree(directory)
   except OSError:
    break
  else:
   break

def prune_dirs ( path , root = None , clutter = ( '.DS_Store' , 'Thumbs.db' ) ) : path = normpath ( path ) if ( root is not None ) : root = normpath ( root ) ancestors = ancestry ( path ) if ( root is None ) : ancestors = [ ] elif ( root in ancestors ) : ancestors = ancestors [ ( ancestors . index ( root ) + 1 ) : ] else : return ancestors . append ( path ) ancestors . reverse ( ) for directory in ancestors : directory = syspath ( directory ) if ( not os . path . exists ( directory ) ) : continue clutter = [ bytestring_path ( c ) for c in clutter ] match_paths = [ bytestring_path ( d ) for d in os . listdir ( directory ) ] if fnmatch_all ( match_paths , clutter ) : try : shutil . rmtree ( directory ) except OSError : break else : break
if path is an empty directory .