From 76ae04a2662a3365159817478ca89ec72cfe3f4f Mon Sep 17 00:00:00 2001 From: gutmet Date: Sat, 8 Dec 2018 20:13:16 +0100 Subject: [PATCH] add function to list all files with extension recursively --- goutil.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/goutil.go b/goutil.go index b436c41..1cfff3c 100644 --- a/goutil.go +++ b/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