Walk a directory/Recursively: Difference between revisions
Content added Content deleted
(→{{header|Go}}: minor update for library change) |
|||
Line 388: | Line 388: | ||
import ( |
import ( |
||
"fmt" |
"fmt" |
||
"path" |
"path/filepath" |
||
"os" |
"os" |
||
) |
) |
||
type MyVisitor struct |
type MyVisitor struct{} // a type to satisfy filepath.Visitor interface |
||
func ( |
func (MyVisitor) VisitDir(string, *os.FileInfo) bool { |
||
return true |
return true |
||
} |
} |
||
func ( |
func (MyVisitor) VisitFile(fp string, _ *os.FileInfo) { |
||
if |
if filepath.Ext(fp) == ".mp3" { |
||
fmt.Println( |
fmt.Println(fp) |
||
} |
} |
||
} |
} |
||
func main() { |
func main() { |
||
filepath.Walk("/", MyVisitor{}, nil) |
|||
}</lang> |
}</lang> |
||