September 2017
Intermediate to advanced
466 pages
9h 33m
English
The most important task that find(1) needs to support is being able to visit all files and sub directories starting from a given directory. So, this section will implement this task in Go. The Go code of traverse.go will be presented in three parts. The first part is the expected preamble:
package main import ( "fmt" "os" "path/filepath" )
The second part is about implementing a function named walkFunction() that will be used as an argument to a Go function named filepath.Walk():
func walkFunction(path string, info os.FileInfo, err error) error {
_, err = os.Stat(path)
if err != nil {
return err
}
fmt.Println(path)
return nil
}
Once again, the os.Stat() function is used because a successful os.Stat() function ...
Read now
Unlock full access