Skip to content

Instantly share code, notes, and snippets.

@nbari
Last active August 29, 2015 14:13
Show Gist options
  • Save nbari/20a2c681781a0036f5af to your computer and use it in GitHub Desktop.
Save nbari/20a2c681781a0036f5af to your computer and use it in GitHub Desktop.
walk directory (Walk does not follow symbolic links)
package main
import (
"flag"
"fmt"
"os"
"path/filepath"
)
func main() {
flag.Parse()
root, err := filepath.Abs(flag.Arg(0))
if err != nil {
panic(err.Error())
}
walkFn := func(path string, info os.FileInfo, err error) error {
if info.IsDir() {
fmt.Printf("Dir: %s\n", path)
} else {
fmt.Printf("File: %s, size: %d bytes\n", path, info.Size())
}
return nil
}
fmt.Printf("root: %s\n", root)
err = filepath.Walk(root, walkFn)
if err != nil {
panic(err.Error())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment