Standard library / io/fs

fs.FormatDirEntry()

Formats an entry for human-readable display, not a machine-readable protocol. Expected stdout: '- a.txt\n'.

Formal Syntax & Structure

go syntaxgo
func FormatDirEntry(dir DirEntry) string

Parameters & Attributes

NameTypeDescription
dirDirEntryDirectory entry or subdirectory path.

Return Value

string

Formats an entry for human-readable display, not a machine-readable protocol.

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() { entries, _ := fs.ReadDir(tree(), "."); fmt.Println(fs.FormatDirEntry(entries[0])) }
Go Reference