-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscan.go
67 lines (60 loc) · 1.26 KB
/
scan.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package main
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
)
var excluded = []string{".git", ".hg", "node_modules", "cache", "src", "lib"}
var look_for_filenames = []string{".resticsync"}
func Scan(directory_path string) []string {
directory_path, _ = filepath.Abs(directory_path)
var dirs = make([]string, 0, 1)
files, err := ioutil.ReadDir(directory_path)
if err != nil {
return []string{}
}
dirs = append(dirs, directory_path)
for _, info := range files {
path := filepath.Join(directory_path, info.Name())
if err != nil {
fmt.Fprintln(os.Stderr, "Error: ", err.Error())
}
if !info.IsDir() {
continue
}
//Exclude dirs
exc := false
for _, excluded := range excluded {
if info.Name() == excluded {
exc = true
break
}
}
if exc {
continue
}
dirs = append(dirs, Scan(path)...)
}
return dirs
}
func LookForFiles(dirs []string) []string {
result := make([]string, 0)
for _, directory_path := range dirs {
files, err := ioutil.ReadDir(directory_path)
if err != nil {
continue
}
for _, info := range files {
if info.IsDir() {
continue
}
for _, lookname := range look_for_filenames {
if info.Name() == lookname {
result = append(result, directory_path)
}
}
}
}
return result
}