Standard library / os

os.DirEntry

Alias for io/fs.DirEntry, describing a directory entry without requiring full metadata for every operation. Example uses a disposable temporary workspace. Expected stdout: 'a.txt false\n'.

Formal Syntax & Structure

go syntaxgo
type DirEntry = fs.DirEntry

Working Example

Example Snippetgo
package main
import (  "fmt"  "os")
func check(e error) {  if e != nil {    panic(e)  }}func seed() { check(os.WriteFile("a.txt", []byte("abc"), 0600)) }func workspace() func() {  root, e := os.MkdirTemp("", "bytemind-go-")  check(e)  old, e := os.Getwd()  check(e)  check(os.Chdir(root))  return func() { check(os.Chdir(old)); check(os.RemoveAll(root)) }}func main() {  defer workspace()()  seed()  d, e := os.ReadDir(".")  check(e)  var x os.DirEntry = d[0]  fmt.Println(x.Name(), x.IsDir())}
Go Reference