Created
March 5, 2020 08:07
go语言列出指定目录的所有文件
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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