Standard library / path/filepath

path/filepath.SkipAll

Callback sentinel to stop all traversal without returning an error from Walk or WalkDir. Example uses a disposable temporary workspace. Expected stdout: '1\n'.

Formal Syntax & Structure

go syntaxgo
var SkipAll error

Working Example

Example Snippetgo
package main
import (  "fmt"  "io/fs"  "os"  "path/filepath")
func check(e error) {  if e != nil {    panic(e)  }}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()()  n := 0  check(filepath.WalkDir(".", func(p string, d fs.DirEntry, e error) error {    if e != nil {      return e    }    n++    return filepath.SkipAll  }))  fmt.Println(n)}
Go Reference