package mainimport ( "fmt" "os" "path/filepath")var Files []stringfunc main() { /* wc, _ := os.Getwd() var directory = flag.String("dir", wc, "which dir you wanna scan") flag.Parse() */ err := Scan("/usr/local/var/www/app") if err == nil { fmt.Println("files:") fmt.Sprintf("%v\n", Files) } else { fmt.Println("errors:") fmt.Fprintf(os.Stderr, "%v", err) }}func Scan(path string) error { err := filepath.Walk(path, func (path string, f os.FileInfo, err error) error { if f == nil { return err } if f.IsDir() { return nil } Files = append(Files, path) return nil }) return err}上述代码并不能将path push到Files全局变量里面,我该怎么办?
- 2 回答
- 0 关注
- 1272 浏览
添加回答
举报
0/150
提交
取消