Standard library / io/fs
fs.FileInfoToDirEntry()
Adapts metadata to a DirEntry; nil metadata returns nil. Expected stdout: 'a.txt false\n'.
Formal Syntax & Structure
go syntaxgo
func FileInfoToDirEntry(info FileInfo) DirEntryParameters & Attributes
| Name | Type | Description |
|---|---|---|
| info | FileInfo | File metadata. |
Return Value
DirEntry
Adapts metadata to a DirEntry; nil metadata returns nil.
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() { i, _ := fs.Stat(tree(), "a.txt") d := fs.FileInfoToDirEntry(i) fmt.Println(d.Name(), d.IsDir())}