Back to Hugo

os.ReadDir

docs/content/en/functions/os/ReadDir.md

0.161.1649 B
Original Source

The os.ReadDir function resolves the path relative to the root of your project directory. A leading path separator (/) is optional.

With this directory structure:

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

This template code:

go-html-template
{{ range readDir "content" }}
  {{ .Name }} → {{ .IsDir }}
{{ end }}

Produces:

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

Note that os.ReadDir is not recursive.

Details of the FileInfo structure are available in the Go documentation.