func GetAllFiles(dirPth string) (files []string, err error) {
fis, err := ioutil.ReadDir(filepath.Clean(filepath.ToSlash(dirPth)))
if err != nil {
return nil, err
}
for _, f := range fis {
_path := filepath.Join(dirPth, f.Name())
if f.IsDir() {
fs, _ := GetAllFiles(_path)
files = append(files, fs...)
continue
}
// 指定格式
switch filepath.Ext(f.Name()) {
case ".png", ".jpg":
files = append(files, _path)
}
}
return files, nil
}
参考:https://blog.csdn.net/robertkun/article/details/78744464