-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist.go
48 lines (44 loc) · 897 Bytes
/
list.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
package main
import (
"io/ioutil"
"log"
"path/filepath"
)
func listFiles(searchPath string) []string {
var files = []string{}
searchPath, err := filepath.Abs(searchPath)
if err != nil {
log.Fatal(err)
}
fis, err := ioutil.ReadDir(searchPath)
if err != nil {
log.Fatal(err)
}
for _, fi := range fis {
fullPath := filepath.Join(searchPath, fi.Name())
if !fi.IsDir() {
files = append(files, fullPath)
}
}
return files
}
func listFilesWalk(searchPath string) []string {
var files = []string{}
searchPath, err := filepath.Abs(searchPath)
if err != nil {
log.Fatal(err)
}
fis, err := ioutil.ReadDir(searchPath)
if err != nil {
log.Fatal(err)
}
for _, fi := range fis {
fullPath := filepath.Join(searchPath, fi.Name())
if !fi.IsDir() {
files = append(files, fullPath)
} else {
files = append(files, listFilesWalk(fullPath)...)
}
}
return files
}