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
|
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)
|
dirInfo, err := os.Stat(dirPath)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -28,29 +28,23 @@ func ListFiles(dirPath string) (*array_list.ArrayList[os.FileInfo], error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
result := array_list.NewArrayList[os.FileInfo]()
|
result := array_list.NewArrayList[string]()
|
||||||
|
|
||||||
if len(dirEntries) > 0 {
|
if len(dirEntries) > 0 {
|
||||||
for _, dirEntry := range dirEntries {
|
for _, dirEntry := range dirEntries {
|
||||||
dirEntryFileInfo, err := dirEntry.Info()
|
result.Add(dirEntry.Name())
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
result.Add(dirEntryFileInfo)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func FindSubFilesByFilter(rootPath string, filter FileFilter) (*array_list.ArrayList[os.FileInfo], error) {
|
func FindSubFilesByFilter(rootPath string, filter FileFilter) (*array_list.ArrayList[string], error) {
|
||||||
result := array_list.NewArrayList[os.FileInfo]()
|
result := array_list.NewArrayList[string]()
|
||||||
|
|
||||||
err := filepath.Walk(rootPath, func(path string, info fs.FileInfo, err error) error {
|
err := filepath.Walk(rootPath, func(path string, info fs.FileInfo, err error) error {
|
||||||
if err == nil && filter(info, path) {
|
if err == nil && filter(info, path) {
|
||||||
result.Add(info)
|
result.Add(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in New Issue