| 1 |
--- |
| 2 |
title: os.Stat |
| 3 |
description: Returns a FileInfo structure describing a file or directory. |
| 4 |
categories: [] |
| 5 |
keywords: [] |
| 6 |
params: |
| 7 |
functions_and_methods: |
| 8 |
aliases: [] |
| 9 |
returnType: os.FileInfo |
| 10 |
signatures: [os.Stat PATH] |
| 11 |
aliases: [/functions/os.stat] |
| 12 |
--- |
| 13 |
|
| 14 |
The `os.Stat` function attempts to resolve the path relative to the root of your project directory. If a matching file or directory is not found, it will attempt to resolve the path relative to the [`contentDir`][]. A leading path separator (`/`) is optional. |
| 15 |
|
| 16 |
```go-html-template |
| 17 |
{{ $f := os.Stat "README.md" }} |
| 18 |
{{ $f.IsDir }} → false (bool) |
| 19 |
{{ $f.ModTime }} → 2021-11-25 10:06:49.315429236 -0800 PST (time.Time) |
| 20 |
{{ $f.Name }} → README.md (string) |
| 21 |
{{ $f.Size }} → 241 (int64) |
| 22 |
|
| 23 |
{{ $d := os.Stat "content" }} |
| 24 |
{{ $d.IsDir }} → true (bool) |
| 25 |
``` |
| 26 |
|
| 27 |
Details of the `FileInfo` structure are available in the [Go documentation][]. |
| 28 |
|
| 29 |
[Go documentation]: https://pkg.go.dev/io/fs#FileInfo |
| 30 |
[`contentDir`]: /configuration/all/#contentdir |