os.ReadDir
Returns an array of FileInfo structures sorted by file name, one element for each directory entry.
- Syntax
- os.ReadDir PATH
- Returns
- os.FileInfo
- Alias
- readDir
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:
content/
├── about.md
├── contact.md
└── news/
├── article-1.md
└── article-2.mdThis template code:
{{ range readDir "content" }}
{{ .Name }} → {{ .IsDir }}
{{ end }}Produces:
about.md → false
contact.md → false
news → trueNote that os.ReadDir is not recursive.
Details of the FileInfo structure are available in the Go documentation.
Last updated:
June 18, 2026
:
Merge commit 'c86d9f4aa8a58931f52df6516f10b67c807505fb' (be780afa7)
Improve this page