package main
import(
"fmt"
"io/ioutil"
)
func main() {
skillfolder := `C:\Users\yejianfeng\Desktop\mxm\skill\`
// 获取所有文件
files, _ := ioutil.ReadDir(skillfolder)
for _,file := range files {
if file.IsDir() {
continue
} else {
fmt.Println(file.Name())
}
}
}
根据楼主的代码改了下,递归获取指定路径下的所有文件,包含所有子目录下的文件,输出基于指定路径的绝对路径
```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