refactor /cmd/prune/main.go#ls to /pkg/fs/ls.go
This commit is contained in:
29
pkg/fs/ls.go
Normal file
29
pkg/fs/ls.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package fs
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path"
|
||||
"sort"
|
||||
)
|
||||
|
||||
func LsD(d string) ([]string, error) {
|
||||
return ls(d, true)
|
||||
}
|
||||
|
||||
func LsF(d string) ([]string, error) {
|
||||
return ls(d, false)
|
||||
}
|
||||
|
||||
func ls(d string, dirs bool) ([]string, error) {
|
||||
entries, err := os.ReadDir(d)
|
||||
|
||||
results := make([]string, 0, len(entries))
|
||||
for i := range entries {
|
||||
if dirs == entries[i].IsDir() {
|
||||
results = append(results, path.Join(d, entries[i].Name()))
|
||||
}
|
||||
}
|
||||
sort.Strings(results)
|
||||
|
||||
return results, err
|
||||
}
|
||||
Reference in New Issue
Block a user