code: def delete_empty_dir(directory):
      
      if os.path.exists(directory):
          if os.path.isdir(directory):
              for d in os.listdir(directory):
                  path = os.path.join(directory, d)
                  if os.path.isdir(path):
                      delete_empty_dir(path)
  
          if not os.listdir(directory):
              os.rmdir(directory)
              print("Remove the empty directory: " + directory)
      else:
          print("The directory is not exist!")
docs: 删除空目录
  
      :param directory: 目录路径