ncmdump-gui/utils/file_util.go

31 lines
558 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package utils
import (
"os"
"path/filepath"
)
func ListFilesFromFolder(root string, ext string) ([]string, error) {
var files []string
// Walk函数会遍历文件树递归地访问每个目录和文件
err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
// 检查是否是文件以及文件后缀是否匹配
if !info.IsDir() && filepath.Ext(path) == "."+ext {
files = append(files, path)
}
return nil
})
if err != nil {
return nil, err
}
return files, nil
}