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())
}
}
}