def delete_empty_folders(check_empty_dir, keep_dir=None):
 ignore_items = []
 sickrage.srCore.srLogger.info((u'Trying to clean any empty folders under ' + check_empty_dir))
 try:
  while (os.path.isdir(check_empty_dir) and (check_empty_dir != keep_dir)):
   check_files = os.listdir(check_empty_dir)
   if ((not check_files) or ((len(check_files) <= len(ignore_items)) and all([(check_file in ignore_items) for check_file in check_files]))):
    try:
     sickrage.srCore.srLogger.info((u'Deleting empty folder: ' + check_empty_dir))
     os.rmdir(check_empty_dir)
     sickrage.srCore.notifiersDict.synoindex_notifier.deleteFolder(check_empty_dir)
    except OSError as e:
     sickrage.srCore.srLogger.warning((u'Unable to delete %s. Error: %r' % (check_empty_dir, repr(e))))
     raise StopIteration
    check_empty_dir = os.path.dirname(check_empty_dir)
   else:
    raise StopIteration
 except StopIteration:
  pass

def delete_empty_folders ( check_empty_dir , keep_dir = None ) : ignore_items = [ ] sickrage . srCore . srLogger . info ( ( u'Trying to clean any empty folders under ' + check_empty_dir ) ) try : while ( os . path . isdir ( check_empty_dir ) and ( check_empty_dir != keep_dir ) ) : check_files = os . listdir ( check_empty_dir ) if ( ( not check_files ) or ( ( len ( check_files ) <= len ( ignore_items ) ) and all ( [ ( check_file in ignore_items ) for check_file in check_files ] ) ) ) : try : sickrage . srCore . srLogger . info ( ( u'Deleting empty folder: ' + check_empty_dir ) ) os . rmdir ( check_empty_dir ) sickrage . srCore . notifiersDict . synoindex_notifier . deleteFolder ( check_empty_dir ) except OSError as e : sickrage . srCore . srLogger . warning ( ( u'Unable to delete %s. Error: %r' % ( check_empty_dir , repr ( e ) ) ) ) raise StopIteration check_empty_dir = os . path . dirname ( check_empty_dir ) else : raise StopIteration except StopIteration : pass
walks backwards up the path and deletes any empty folders found .