Standard library / io/fs

fs.SkipDir

WalkDir callback sentinel to skip a directory; on a nondirectory it skips the rest of the containing directory. Expected stdout: '.\na.txt\nsub\n<nil>\n'.

Formal Syntax & Structure

go syntaxgo
var SkipDir 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() {  e := fs.WalkDir(tree(), ".", func(p string, d fs.DirEntry, e error) error {    if e != nil {      return e    }    fmt.Println(p)    if p == "sub" {      return fs.SkipDir    }    return nil  })  fmt.Println(e)}
Go Reference