hugo/docs/content/en/functions/os/ReadDir.md
Bjørn Erik Pedersen 5fd1e74903
Merge commit '9b0050e9aabe4be65c78ccf292a348f309d50ccd' as 'docs'
```
git subtree add --prefix=docs/ https://github.com/gohugoio/hugoDocs.git master --squash
```

Closes #11925
2024-01-27 10:48:57 +01:00

1.1 KiB

title description categories keywords action aliases
os.ReadDir Returns an array of FileInfo structures sorted by file name, one element for each directory entry.
aliases related returnType signatures
readDir
functions/os/FileExists
functions/os/Getenv
functions/os/ReadFile
functions/os/Stat
os.FileInfo
os.ReadDir PATH
/functions/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.md

This template code:

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

Produces:

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.

For more information on using readDir and readFile in your templates, see Local File Templates.