1
0
Fork 0
mirror of https://github.com/vbatts/sl-feeds.git synced 2025-07-25 16:30:28 +00:00

util: file path finder

Convenience to walk a directory tree looking for a file like
"ChangeLog.txt"

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
Vincent Batts 2017-01-29 15:50:51 -05:00
parent 0cd4c2fee6
commit e646c9daef
Signed by: vbatts
GPG key ID: 10937E57733F1362
2 changed files with 37 additions and 0 deletions

23
util/find.go Normal file
View file

@ -0,0 +1,23 @@
package util
import (
"os"
"path/filepath"
)
func FindFiles(root, name string) (paths []string, err error) {
paths = []string{}
err = filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if filepath.Base(path) == name {
paths = append(paths, path)
}
return nil
})
if err != nil {
return nil, err
}
return paths, nil
}