Debian Codegraph @

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

raw
1 ---
2 title: os.ReadDir
3 description: Returns an array of FileInfo structures sorted by file name, one element for each directory entry.
4 categories: []
5 keywords: []
6 params:
7 functions_and_methods:
8 aliases: [readDir]
9 returnType: os.FileInfo
10 signatures: [os.ReadDir PATH]
11 aliases: [/functions/readdir]
12 ---
13
14 The `os.ReadDir` function resolves the path relative to the root of your project directory. A leading path separator (`/`) is optional.
15
16 With this directory structure:
17
18 ```tree
19 content/
20 ├── about.md
21 ├── contact.md
22 └── news/
23 ├── article-1.md
24 └── article-2.md
25 ```
26
27 This template code:
28
29 ```go-html-template
30 {{ range readDir "content" }}
31 {{ .Name }} → {{ .IsDir }}
32 {{ end }}
33 ```
34
35 Produces:
36
37 ```html
38 about.md → false
39 contact.md → false
40 news → true
41 ```
42
43 Note that `os.ReadDir` is not recursive.
44
45 Details of the `FileInfo` structure are available in the [Go documentation][].
46
47 [Go documentation]: https://pkg.go.dev/io/fs#FileInfo