The os.Stat function in Hugo

October 29, 2018, last updated October 30, 2018

The os.Stat function in Hugo (see the docs) is useful for getting information about a particular file. For example, say I wanted to get the info on this page:

{{ $file := "content/post/the-os-stat-function-in-hugo.md" }}
{{ $stat := os.Stat $file }}

File Name: {{ $stat.Name }}
File Size: {{ $stat.Size }} bits
File Mode: {{ $stat.Mode }}
File ModTime: {{ $stat.ModTime }}
File IsDir: {{ $stat.IsDir }}

I’ve added some formatting to pretty things up, so the above code would give this output:

File Name: the-os-stat-function-in-hugo.md

File Size: 746 bits

File Mode: -rw-r--r--

File ModTime: 2018-11-13 05:46:55.053749511 +0000 UTC

File IsDir: false