Standard library / io/fs
fs.FileInfo
Metadata snapshot with name, size, mode, modification time, directory status and system-specific data. Expected stdout: 'a.txt 2\n'.
Formal Syntax & Structure
go syntaxgo
type FileInfo interface { Name() string Size() int64 Mode() FileMode ModTime() time.Time IsDir() bool Sys() any}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() { var i fs.FileInfo; i, _ = fs.Stat(tree(), "a.txt"); fmt.Println(i.Name(), i.Size()) }