add function to list all files with extension recursively

This commit is contained in:
gutmet 2018-12-08 20:13:16 +01:00
parent d86c65a103
commit 76ae04a266

View File

@ -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