feature: sub file finders returns file names now
parent
6215b4e87f
commit
4a3e5818a1
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue