获取目录中所有文件

jianfengye110 · · 12176 次点击
根据楼主的代码改了下,递归获取指定路径下的所有文件,包含所有子目录下的文件,输出基于指定路径的绝对路径 ```go //listFile is aimming to list all files in the specific directory package main import ( "fmt" "io/ioutil" ) func main(){ folder := "." listFile(folder) } func listFile(folder string){ files, _ := ioutil.ReadDir(folder) //specify the current dir for _,file := range files{ if file.IsDir(){ listFile(folder + "/" + file.Name()) }else{ fmt.Println(folder + "/" + file.Name()) } } } ```
#1