code: def remove_empty_dir(path):
      
      try:
          if not os.path.isdir(path):
              return
  
          files = os.listdir(path)
  
          # if folder empty, delete it
          if len(files) == 0:
              os.rmdir(path)
  
          # remove empty subdirectory
          elif len(files) > 0:
              for f in files:
                  abspath = os.path.join(path, f)
                  if os.path.isdir(abspath):
                      remove_empty_dir(abspath)
      except OSError as e:
          if e.errno == errno.ENOTEMPTY:
              pass
docs: Function to remove empty folders