Walk a directory/Recursively: Difference between revisions
→{{header|Go}}: update required for library change. I also made the solution conform better to the task requirement to match a pattern
(→{{header|Python}}: put back fnmatch,filter and add a link to its explanation) |
(→{{header|Go}}: update required for library change. I also made the solution conform better to the task requirement to match a pattern) |
||
Line 827:
)
if err != nil {
fmt.Println(err) // can't walk here,
return nil // but continue walking elsewhere
return true▼
}
if !fi.IsRegular() {
return nil // not a file. ignore.
▲func (MyVisitor) VisitFile(fp string, _ *os.FileInfo) {
}
matched, err := filepath.Match("*.mp3", fi.Name)
if err != nil {
fmt.Println(err) // malformed pattern
return err // this is fatal.
}
if matched {
fmt.Println(fp)
}
}
func main() {
filepath.Walk("/",
}</lang>
|