Skip to content

Instantly share code, notes, and snippets.

@geekgogo
Created March 5, 2020 08:07
go语言列出指定目录的所有文件
package main
import (
"flag"
"fmt"
"os"
"path/filepath"
)
func getFilelist(path string) {
err := filepath.Walk(path, func(path string, f os.FileInfo, err error) error {
if f == nil {
return err
}
if f.IsDir() {
return nil
}
println(path)
return nil
})
if err != nil {
fmt.Printf("filepath.Walk() returned %v\n", err)
}
}
func main() {
flag.Parse()
root := flag.Arg(0)
getFilelist(root)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment