Rev 27 | Rev 37 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
28 | - | 1 | //usr/bin/env go run $0 $@; exit $? |
27 | - | 2 | package main |
3 | |||
4 | import ( |
||
5 | "fmt" |
||
6 | "io/ioutil" |
||
7 | "log" |
||
8 | "os" |
||
9 | ) |
||
10 | |||
28 | - | 11 | // ============================================================================= |
12 | // Functions |
||
13 | // ============================================================================= |
||
14 | |||
27 | - | 15 | func traverse(s string) { |
16 | curdir, err := os.Getwd() |
||
17 | if err := os.Chdir(s); err != nil { |
||
18 | log.Fatal(err) |
||
19 | } |
||
20 | if err != nil { |
||
21 | log.Fatal(err) |
||
22 | } |
||
23 | curdir2, err := os.Getwd() |
||
24 | files, err := ioutil.ReadDir(curdir2) |
||
25 | if err != nil { |
||
26 | log.Fatal(err) |
||
27 | } |
||
28 | for _, f := range files { |
||
29 | fmt.Println (curdir2 + "/" + f.Name()) |
||
30 | //fmt.Println(f.Name()) |
||
31 | fi, err := os.Stat(f.Name()) |
||
32 | if err != nil { |
||
33 | log.Fatal(err) |
||
34 | } |
||
35 | mode := fi.Mode(); |
||
36 | if mode.IsDir() { |
||
37 | traverse(fi.Name()) |
||
38 | } |
||
39 | } |
||
40 | os.Chdir(curdir) |
||
41 | } |
||
42 | |||
43 | func start_traverse(s string) { |
||
44 | fmt.Println(s) |
||
45 | traverse(s) |
||
46 | } |
||
47 | |||
28 | - | 48 | // ============================================================================= |
49 | // MAIN |
||
50 | // ============================================================================= |
||
51 | |||
27 | - | 52 | func main() { |
28 | - | 53 | if len(os.Args) < 2 { |
54 | log.Fatal("Give a directory as argument") |
||
55 | } |
||
27 | - | 56 | arg := os.Args[1] |
57 | fi, err := os.Stat(arg) |
||
58 | if err != nil { |
||
59 | log.Fatal(err) |
||
60 | } |
||
61 | if fi.IsDir() { |
||
62 | start_traverse(arg) |
||
63 | } else { |
||
64 | fmt.Println("Geen dir") |
||
65 | } |
||
66 | |||
67 | } |