Commit 683e2fd5 authored by Erwin Oegema's avatar Erwin Oegema Committed by Brad Fitzpatrick

path/filepath: change example to print the correct path on failure

This change makes errors in the example code a bit better, as it's no use to show the root dir when an error occurs walking a subdirectory or file.

Change-Id: I546276e9b151fabba5357258f03bfbd47a508201
GitHub-Last-Rev: 398c1eeb6164a7edc6fdee8cb8c17c3bd0b649ef
GitHub-Pull-Request: golang/go#24536
Reviewed-on: https://go-review.googlesource.com/102535Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 665af046
...@@ -80,13 +80,14 @@ func ExampleJoin() { ...@@ -80,13 +80,14 @@ func ExampleJoin() {
// a/b/c // a/b/c
// a/b/c // a/b/c
} }
func ExampleWalk() { func ExampleWalk() {
dir := "dir/to/walk" dir := "dir/to/walk"
subDirToSkip := "skip" // dir/to/walk/skip subDirToSkip := "skip" // dir/to/walk/skip
err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error { err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
if err != nil { if err != nil {
fmt.Printf("prevent panic by handling failure accessing a path %q: %v\n", dir, err) fmt.Printf("prevent panic by handling failure accessing a path %q: %v\n", path, err)
return err return err
} }
if info.IsDir() && info.Name() == subDirToSkip { if info.IsDir() && info.Name() == subDirToSkip {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment