Standard library / io/fs
fs.ReadDirFile
Open directory file interface; positive n returns batches and EOF when exhausted, nonpositive n returns all remaining entries. Expected stdout: '1 <nil>\n'.
Formal Syntax & Structure
go syntaxgo
type ReadDirFile interface { File
ReadDir(n int) ([]DirEntry, 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() { f, _ := tree().Open(".") defer f.Close() d := f.(fs.ReadDirFile) entries, e := d.ReadDir(1) fmt.Println(len(entries), e)}