Rev 28 | Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
27 | - | 1 | package main |
2 | |||
3 | import ( |
||
4 | "fmt" |
||
5 | "io/ioutil" |
||
6 | "log" |
||
7 | "os" |
||
8 | ) |
||
9 | |||
10 | func traverse(s string) { |
||
11 | curdir, err := os.Getwd() |
||
12 | if err := os.Chdir(s); err != nil { |
||
13 | log.Fatal(err) |
||
14 | } |
||
15 | if err != nil { |
||
16 | log.Fatal(err) |
||
17 | } |
||
18 | curdir2, err := os.Getwd() |
||
19 | files, err := ioutil.ReadDir(curdir2) |
||
20 | if err != nil { |
||
21 | log.Fatal(err) |
||
22 | } |
||
23 | for _, f := range files { |
||
24 | fmt.Println (curdir2 + "/" + f.Name()) |
||
25 | //fmt.Println(f.Name()) |
||
26 | fi, err := os.Stat(f.Name()) |
||
27 | if err != nil { |
||
28 | log.Fatal(err) |
||
29 | } |
||
30 | mode := fi.Mode(); |
||
31 | if mode.IsDir() { |
||
32 | traverse(fi.Name()) |
||
33 | } |
||
34 | } |
||
35 | os.Chdir(curdir) |
||
36 | } |
||
37 | |||
38 | func start_traverse(s string) { |
||
39 | fmt.Println(s) |
||
40 | traverse(s) |
||
41 | } |
||
42 | |||
43 | func main() { |
||
44 | arg := os.Args[1] |
||
45 | fi, err := os.Stat(arg) |
||
46 | if err != nil { |
||
47 | log.Fatal(err) |
||
48 | } |
||
49 | if fi.IsDir() { |
||
50 | start_traverse(arg) |
||
51 | } else { |
||
52 | fmt.Println("Geen dir") |
||
53 | } |
||
54 | |||
55 | } |