Skip to content

Instantly share code, notes, and snippets.

@innermond
Created January 4, 2018 14:51
Show Gist options
  • Save innermond/568e9c3ab9dc2f6854ae706704f8c782 to your computer and use it in GitHub Desktop.
Save innermond/568e9c3ab9dc2f6854ae706704f8c782 to your computer and use it in GitHub Desktop.
Walk all the way down the folder hierachy
package main
import (
"fmt"
"os"
"os/user"
"path/filepath"
)
func main() {
usr, _ := user.Current()
p := filepath.Join(usr.HomeDir, <path segment>, <other path segment>)
filepath.Walk(p, func(fn string, fi os.FileInfo, err error) error {
if err != nil {
fmt.Println(err)
return err
}
fn = fn[len(p):]
fmt.Printf("%s %v\n", fn, fi.IsDir())
return nil
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment