Skip to content

Instantly share code, notes, and snippets.

@hayajo
Created January 31, 2014 04:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hayajo/8726745 to your computer and use it in GitHub Desktop.
Save hayajo/8726745 to your computer and use it in GitHub Desktop.
ディレクトリを再帰的にホゲホゲする
package main
import(
"fmt"
"path/filepath"
"os"
)
var handler filepath.WalkFunc = func(path string, info os.FileInfo, err error) error {
t := new(string)
if info.IsDir() {
*t = "d"
} else {
*t = "f"
}
fmt.Printf("%s: %s\n", *t, path)
return nil
}
func main() {
path := new(string)
if len(os.Args) == 1 {
*path = "."
} else {
*path = os.Args[1]
}
filepath.Walk(*path, handler)
// 匿名関数
/* filepath.Walk(*path, func(path string, info os.FileInfo, err error) error { */
/* t := new(string) */
/* if info.IsDir() { */
/* *t = "d" */
/* } else { */
/* *t = "f" */
/* } */
/* fmt.Printf("%s: %s\n", *t, path) */
/* return nil */
/* }) */
// newで生成
/* h := new(filepath.WalkFunc) */
/* *h = func(path string, info os.FileInfo, err error) error { */
/* t := new(string) */
/* if info.IsDir() { */
/* *t = "d" */
/* } else { */
/* *t = "f" */
/* } */
/* fmt.Printf("%s: %s\n", *t, path) */
/* return nil */
/* } */
/* filepath.Walk(*path, *h) */
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment