It's easy to traverse a folder in Python, and I need that in the go world. Looking for a document, which has this function (specific reference here: http://golang.org/pkg/path/filepath/) ...
OK, no nonsense, I also want to go to bed early, directly on the code.
The code is as follows:
Copy Code code as follows:
/*
File:getFilelist.go
Author:mike
E-mail:mike_zhang@live.com
*/
Package Main
Import (
"Path/filepath"
"OS"
"FMT"
"Flag"
)
Func getfilelist (path string) {
err: = FilePath. Walk (Path, func (path string, f OS). FileInfo, err Error) error {
if (f = = nil) {return err}
& nbsp; 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)
}
The operation effect is as follows:
Well, that's all, I hope to help you.