File tree Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Original file line number Diff line number Diff line change 29
29
30
30
package paths
31
31
32
- import "io/ioutil"
32
+ import (
33
+ "io/ioutil"
34
+ )
35
+
36
+ // ReadDirFilter is a filter for Path.ReadDir and Path.ReadDirRecursive methods.
37
+ // The filter should return true to accept a file or false to reject it.
38
+ type ReadDirFilter func (file * Path ) bool
33
39
34
40
// ReadDir returns a PathList containing the content of the directory
35
- // pointed by the current Path
36
- func (p * Path ) ReadDir () (PathList , error ) {
41
+ // pointed by the current Path. The resulting list is filtered by the given filters chained.
42
+ func (p * Path ) ReadDir (filters ... ReadDirFilter ) (PathList , error ) {
37
43
infos , err := ioutil .ReadDir (p .path )
38
44
if err != nil {
39
45
return nil , err
40
46
}
41
47
paths := PathList {}
48
+ fileLoop:
42
49
for _ , info := range infos {
43
50
path := p .Join (info .Name ())
51
+ for _ , filter := range filters {
52
+ if ! filter (path ) {
53
+ continue fileLoop
54
+ }
55
+ }
44
56
paths .Add (path )
45
57
}
46
58
return paths , nil
You can’t perform that action at this time.
0 commit comments