先学一学GO语言实用的一面。
package main import ( "path/filepath" "flag" "os" "fmt" ) func getFileList(path string) { err := filepath.Walk(path, func(path string, f os.FileInfo, err error) error { if (f == nil) {return err} if f.IsDir() {return nil} println(path) return nil }) if err != nil { fmt.Printf("filepath.Walk() returned %v\n", err) } } func main() { userFile := "test.txt" fout, err := os.Create(userFile) defer fout.Close() if err != nil { fmt.Println(userFile, err) return } for i:=0; i<10; i++ { fout.WriteString("Just a test!\r\n") fout.Write([]byte("Just a array string!\r\n")) } fin, err := os.Open(userFile) defer fin.Close() if err != nil { fmt.Println(userFile, err) return } buf := make([]byte, 1024) for { n, _ := fin.Read(buf) if 0 == n { break } os.Stdout.Write(buf[:n]) } flag.Parse() root := flag.Arg(0) getFileList(root) }