Last active
August 29, 2015 14:13
-
-
Save nbari/20a2c681781a0036f5af to your computer and use it in GitHub Desktop.
walk directory (Walk does not follow symbolic links)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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