-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdirs.go
47 lines (44 loc) · 870 Bytes
/
dirs.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
39
40
41
42
43
44
45
46
47
package main
import (
"os"
"path/filepath"
)
func IsDir(path string) (bool, error) {
var r bool
i, err := os.Stat(path)
if err == nil {
r = i.IsDir()
}
return r, err
}
func (app *fsex) GetSubDirs(path string, filter FileFilter) ([]string, error) {
var r []string
isDir, err := IsDir(path)
if err == nil && isDir {
var t = []string{path}
var entries []os.DirEntry
entries, err = os.ReadDir(path)
if err == nil {
for _, d := range entries {
if d.IsDir() {
p := filepath.Join(path, d.Name())
if filter == nil || !filter.Match(p) {
var subdirs []string
subdirs, err = app.GetSubDirs(p, filter)
if err != nil {
Printf("Error: %s", err)
break
}
t = append(t, subdirs...)
} else {
Debugf(`ignore "%s"`, p)
}
}
}
if err == nil {
r = t
}
}
}
return r, err
}