利于
filepath.Glob
,自己可以免去寫遞歸方法,方便省事。
package utils
import (
"io/ioutil"
"os"
"path/filepath"
"strings"
)
//GetAllFileIncludeSubFolder 遞歸獲取某個目錄下的所有文件
func GetAllFileIncludeSubFolder(folder string) ([]string, error) {
searchPath := folder
if strings.HasSuffix(folder, "/") {
searchPath = searchPath + "*"
} else {
searchPath = searchPath + "/*"
}
return filepath.Glob(searchPath)
}