This recipe will show you how to list directory content.
Listing a directory
How to do it...
- Open the console and create the folder chapter06/recipe05.
- Navigate to the directory.
- Create a directory named folder.
- Create the listdir.go file with the following content:
package main
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
)
func main() {
fmt.Println("List by ReadDir")
listDirByReadDir(".")
fmt.Println()
fmt.Println("List by Walk")
listDirByWalk(".")
}
func listDirByWalk(path string) {
filepath.Walk(path, func...