-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.go
38 lines (30 loc) · 829 Bytes
/
list.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package path
import (
"os"
)
// List is just a convience function to get a slice of files
func List(inputPath string, levelsDeep uint8, includeRoot bool, filters ...EntriesFilter) ([]Entry, error) {
var entry, err = NewEntry(inputPath, levelsDeep, filters...)
if err != nil {
return nil, err
}
files, err := entry.Flatten(includeRoot)
if err != nil {
return nil, err
}
var filteredFiles []Entry
// we filter here again because populateChildren may return dirs that do not match the filter
FileLoop:
for _, file := range files {
if file.IsDir() || file.FileInfo.Mode()&os.ModeSymlink == os.ModeSymlink {
for _, fn := range filters {
var accepted = fn.filter(file)
if !accepted {
continue FileLoop
}
}
}
filteredFiles = append(filteredFiles, file)
}
return filteredFiles, nil
}