add function to list all files with extension recursively
This commit is contained in:
parent
d86c65a103
commit
76ae04a266
15
goutil.go
15
goutil.go
|
@ -62,6 +62,21 @@ func ListFilesExt(dir string, ext string) []string {
|
|||
return list
|
||||
}
|
||||
|
||||
func RecListFilesExt(dir string, ext string) []string {
|
||||
list := make([]string, 0)
|
||||
traverse := func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if info.IsDir() {
|
||||
list = append(list, ListFilesExt(path, ext)...)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
filepath.Walk(dir, traverse)
|
||||
return list
|
||||
}
|
||||
|
||||
func PathExists(path string) bool {
|
||||
if _, err := os.Stat(path); os.IsNotExist(err) {
|
||||
return false
|
||||
|
|
Loading…
Reference in New Issue
Block a user