Golang iterates over all files under a folder

func GetAllFile(pathname string) error {
    rd, err := ioutil.ReadDir(pathname)
    for _, fi := range rd {
        if fi.IsDir() {
            fmt.Printf("[%s]\n", pathname+"\\"+fi.Name())
            GetAllFile(pathname + fi.Name() + "\\")
        } else {
            fmt.Println(fi.Name())
        }
    }
    return err
}

Leave a Reply

Your email address will not be published.

en_USEnglish