Standard library / io/fs

fs.FormatFileInfo()

Formats metadata for humans; uses timestamp, mode, size and name. Do not rely on format as a stable wire protocol. Expected stdout: '-rw-r--r-- 2 2024-01-02 00:00:00 a.txt\n'.

Formal Syntax & Structure

go syntaxgo
func FormatFileInfo(info FileInfo) string

Parameters & Attributes

NameTypeDescription
infoFileInfoFile metadata.

Return Value

string

Formats metadata for humans; uses timestamp, mode, size and name.

Working Example

Example Snippetgo
package main
import (  "fmt"  "io/fs"  "testing/fstest"  "time")
func tree() fstest.MapFS {  return fstest.MapFS{"a.txt": &fstest.MapFile{Data: []byte("ok"), Mode: 0644, ModTime: time.Date(2024, 1, 2, 0, 0, 0, 0, time.UTC)}, "sub/b.txt": &fstest.MapFile{Data: []byte("go"), Mode: 0644}}}func main() { info, _ := fs.Stat(tree(), "a.txt"); fmt.Println(fs.FormatFileInfo(info)) }
Go Reference