golang遍历文件夹

golang遍历文件夹:

func main() {
    //方式一
    filepath.Walk("temp/", func (path string, info os.FileInfo, err error) error {
        fmt.Println(path)
        return nil
    })

    //方式二
    getFileList("temp/")
}

func getFileList(path string) {
    fs,_:= ioutil.ReadDir(path)
    for _,file:=range fs{
        if file.IsDir(){
            fmt.Println(path+file.Name())
            getFileList(path+file.Name()+"/")
        }else{
            fmt.Println(path+file.Name())
        }
    }
}

这篇博客纯属充数~~~~~~~

猜你喜欢

转载自www.cnblogs.com/xbblogs/p/10981070.html