Standard library / io/fs
fs.DirEntry
Directory listing entry with base name, directory flag, type bits and Info method; Info can fail independently. Expected stdout: 'a.txt false\n'.
Formal Syntax & Structure
go syntaxgo
type DirEntry interface { Name() string
IsDir() bool
Type() FileMode
Info() (FileInfo, error)}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() { d, _ := fs.ReadDir(tree(), ".") var e fs.DirEntry = d[0] fmt.Println(e.Name(), e.IsDir())}