September 2017
Intermediate to advanced
466 pages
9h 33m
English
Although it is good to be able to visit everything, there are times when you want to visit only directories and not files. So, in this subsection, we will modify traverse.go in order to still visit everything but only print the directory names. The name of the new program will be traverseDir.go. The only part of traverse.go that needs to change is the definition of the walkFunction():
func walkFunction(path string, info os.FileInfo, err error) error {
fileInfo, err := os.Stat(path)
if err != nil {
return err
}
mode := fileInfo.Mode()
if mode.IsDir() {
fmt.Println(path)
}
return nil
}
As you can see, here you need to use the information returned by the os.Stat() function call in order to check whether you are dealing ...
Read now
Unlock full access