Created
January 31, 2014 04:47
-
-
Save hayajo/8726745 to your computer and use it in GitHub Desktop.
ディレクトリを再帰的にホゲホゲする
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( | |
"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