Created
August 16, 2014 15:11
-
-
Save ifels/5f034af0e1cc114e2ff7 to your computer and use it in GitHub Desktop.
golang file list
This file contains hidden or 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" | |
"strings" | |
) | |
var ( | |
total int | |
) | |
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 | |
} | |
endsWith := strings.HasSuffix(path, ".go") // true | |
test := strings.HasSuffix(path, "_test.go") | |
if endsWith && !test { | |
total++ | |
println(path) | |
} | |
return nil | |
}) | |
if err != nil { | |
fmt.Printf("filepath.Walk() returned %v\n", err) | |
} | |
} | |
func main() { | |
total = 0 | |
flag.Parse() | |
root := flag.Arg(0) | |
getFilelist(root) | |
println("total = ", total) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment