feature: sub file finders returns file names now

master
amorozov 2024-06-30 01:11:25 +03:00
parent 6215b4e87f
commit 4a3e5818a1
1 changed files with 6 additions and 12 deletions

View File

@ -11,7 +11,7 @@ import (
type FileFilter func(fileInfo os.FileInfo, fileName string) bool
func ListFiles(dirPath string) (*array_list.ArrayList[os.FileInfo], error) {
func ListFiles(dirPath string) (*array_list.ArrayList[string], error) {
dirInfo, err := os.Stat(dirPath)
if err != nil {
@ -28,29 +28,23 @@ func ListFiles(dirPath string) (*array_list.ArrayList[os.FileInfo], error) {
return nil, err
}
result := array_list.NewArrayList[os.FileInfo]()
result := array_list.NewArrayList[string]()
if len(dirEntries) > 0 {
for _, dirEntry := range dirEntries {
dirEntryFileInfo, err := dirEntry.Info()
if err != nil {
return nil, err
}
result.Add(dirEntryFileInfo)
result.Add(dirEntry.Name())
}
}
return result, nil
}
func FindSubFilesByFilter(rootPath string, filter FileFilter) (*array_list.ArrayList[os.FileInfo], error) {
result := array_list.NewArrayList[os.FileInfo]()
func FindSubFilesByFilter(rootPath string, filter FileFilter) (*array_list.ArrayList[string], error) {
result := array_list.NewArrayList[string]()
err := filepath.Walk(rootPath, func(path string, info fs.FileInfo, err error) error {
if err == nil && filter(info, path) {
result.Add(info)
result.Add(path)
}
return err