code: def make_directory_index(title: str, directory_path: Path):
      index_file = directory_path / "index.rst"
      directory_rsts = sorted(directory_path.glob("*.rst"))
      subdirs = sorted(
          [f for f in directory_path.iterdir() if f.is_dir()]
      )
      with open(index_file, "w") as f:
          print(title, file=f)
          print("=" * len(title), file=f)
          print("\n.. toctree::\n", file=f)
          for subdir in subdirs:
              print(f"    {subdir.stem}/index.rst", file=f)
          for rst in directory_rsts:
              if rst.stem == "index":
                  continue
              print(f"    {rst.stem}", file=f)
  
imports: from pathlib import Path
label_desc: Use image node_id 4 for calling a global function with example usage: make_directory_index(title, directory_path) without return types