os.ReadDir

os.ReadDir 函數會解析相對於專案根目錄的路徑。可以選擇性地使用路徑分隔符(/)。

使用以下目錄結構:

content/
├── about.md
├── contact.md
└── news/
    ├── article-1.md
    └── article-2.md

以下範本程式碼:

{{ range readDir "content" }}
  {{ .Name }}{{ .IsDir }}
{{ end }}

輸出結果為:

about.md → false
contact.md → false
news → true

請注意,os.ReadDir 不是遞迴式的。

有關 FileInfo 結構的詳細資訊,請參閱 Go 文檔