Subversion Repositories svn.Prod repos

Rev

Rev 28 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

package main

import (
    "fmt"
    "io/ioutil"
     "log"
    "os"
)

func traverse(s string) {
        curdir, err :=  os.Getwd()
        if err := os.Chdir(s); err != nil {
                log.Fatal(err)
        }
        if err != nil {
                log.Fatal(err)
        }
        curdir2, err := os.Getwd()
        files, err := ioutil.ReadDir(curdir2)
        if err != nil {
                log.Fatal(err)
        }
        for _, f := range files {
                fmt.Println (curdir2 + "/" + f.Name())
                //fmt.Println(f.Name())
                fi, err := os.Stat(f.Name())
                if err != nil {
                        log.Fatal(err)
                }
                mode := fi.Mode();
                if mode.IsDir() {
                        traverse(fi.Name())
                }
        }
        os.Chdir(curdir)
}

func start_traverse(s string) {
        fmt.Println(s)
        traverse(s)
}

func main() {
        arg := os.Args[1]
        fi, err := os.Stat(arg)
        if err != nil {
                log.Fatal(err)
        }
        if fi.IsDir() {
                start_traverse(arg)
        } else {
                fmt.Println("Geen dir")
        }

}