mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-25 22:00:58 +02:00
Merge commit '9b0050e9aabe4be65c78ccf292a348f309d50ccd' as 'docs'
``` git subtree add --prefix=docs/ https://github.com/gohugoio/hugoDocs.git master --squash ``` Closes #11925
This commit is contained in:
51
docs/content/en/functions/os/ReadDir.md
Normal file
51
docs/content/en/functions/os/ReadDir.md
Normal file
@@ -0,0 +1,51 @@
|
||||
---
|
||||
title: os.ReadDir
|
||||
description: Returns an array of FileInfo structures sorted by file name, one element for each directory entry.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [readDir]
|
||||
related:
|
||||
- functions/os/FileExists
|
||||
- functions/os/Getenv
|
||||
- functions/os/ReadFile
|
||||
- functions/os/Stat
|
||||
returnType: os.FileInfo
|
||||
signatures: [os.ReadDir PATH]
|
||||
aliases: [/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:
|
||||
|
||||
```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](https://pkg.go.dev/io/fs#FileInfo).
|
||||
|
||||
For more information on using `readDir` and `readFile` in your templates, see [Local File Templates](/templates/files).
|
Reference in New Issue
Block a user