mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-21 21:35:28 +02:00
Merge commit '8d9511a08f14260cbfb73119e4afae50e5a9966d'
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
---
|
||||
title: os.Stat
|
||||
description: Gets a file information of a given path.
|
||||
description: Returns a FileInfo structure describing a file or directory.
|
||||
date: 2018-08-07
|
||||
publishdate: 2018-08-07
|
||||
lastmod: 2018-08-07
|
||||
lastmod: 2021-11-26
|
||||
categories: [functions]
|
||||
menu:
|
||||
docs:
|
||||
@@ -12,21 +12,21 @@ keywords: [files]
|
||||
signature: ["os.Stat PATH"]
|
||||
workson: []
|
||||
hugoversion:
|
||||
relatedfuncs: [readDir]
|
||||
relatedfuncs: ['os.FileExists','os.ReadDir','os.ReadFile']
|
||||
deprecated: false
|
||||
aliases: []
|
||||
---
|
||||
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`]({{< relref "getting-started/configuration#contentdir">}}). A leading path separator (`/`) is optional.
|
||||
|
||||
If your current project working directory has a single file named `README.txt` (30 bytes):
|
||||
```
|
||||
{{ $stat := os.Stat "README.txt" }}
|
||||
{{ $stat.Name }} → "README.txt"
|
||||
{{ $stat.Size }} → 30
|
||||
```go-html-template
|
||||
{{ $f := os.Stat "README.md" }}
|
||||
{{ $f.IsDir }} --> false (bool)
|
||||
{{ $f.ModTime }} --> 2021-11-25 10:06:49.315429236 -0800 PST (time.Time)
|
||||
{{ $f.Name }} --> README.md (string)
|
||||
{{ $f.Size }} --> 241 (int64)
|
||||
|
||||
{{ $d := os.Stat "content" }}
|
||||
{{ $d.IsDir }} --> true (bool)
|
||||
```
|
||||
|
||||
Function [`os.Stat`][Stat] returns [`os.FileInfo`][osfileinfo].
|
||||
For further information of `os.FileInfo`, see [golang page][osfileinfo].
|
||||
|
||||
|
||||
[Stat]: /functions/os.Stat/
|
||||
[osfileinfo]: https://golang.org/pkg/os/#FileInfo
|
||||
Details of the `FileInfo` structure are available in the [Go documentation](https://pkg.go.dev/io/fs#FileInfo).
|
||||
|
Reference in New Issue
Block a user