-
Notifications
You must be signed in to change notification settings - Fork 10
/
walk.go
44 lines (37 loc) · 788 Bytes
/
walk.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
//http://weekly.golang.org/doc/go1.html#path_filepath
import "fmt"
import "path/filepath"
import "os"
import "log"
/**
* okay this works really well
*
* you can recurse the folder if you want or not
* just set Recurse = true|false
*
**/
//TODO define the walk function outside of main body and return it
func main() {
OrgPath := "/Volumes/HD2/temp"
Recurse := true
walkFn := func(path string, info os.FileInfo, err error) error {
stat, err := os.Stat(path)
if err != nil {
return err
}
if stat.IsDir() && path != OrgPath && !Recurse {
fmt.Println("skipping dir:", path)
return filepath.SkipDir
}
if err != nil {
return err
}
fmt.Println(path)
return nil
}
err := filepath.Walk(OrgPath, walkFn)
if err != nil {
log.Fatal(err)
}
}