WalkPathFunc walks the directory 'dir' and collects all path names matched by func f. If the path is a directory, it will set the bool argument to true. Returns empty string slice if nothing found, otherwise returns all matched path names.
(dir string, f func(string, bool) bool)
| 35 | // func f. If the path is a directory, it will set the bool argument to true. |
| 36 | // Returns empty string slice if nothing found, otherwise returns all matched path names. |
| 37 | func WalkPathFunc(dir string, f func(string, bool) bool) []string { |
| 38 | var list []string |
| 39 | err := filepath.Walk(dir, func(path string, fi os.FileInfo, err error) error { |
| 40 | if err != nil { |
| 41 | return err |
| 42 | } |
| 43 | if f(path, fi.IsDir()) { |
| 44 | list = append(list, path) |
| 45 | } |
| 46 | return nil |
| 47 | }) |
| 48 | if err != nil { |
| 49 | glog.Errorf("Error while scanning %q: %s", dir, err) |
| 50 | } |
| 51 | return list |
| 52 | } |
| 53 | |
| 54 | // FindFilesFunc walks the directory 'dir' and collects all file names matched by |
| 55 | // func f. It will skip over directories. |