Skip to content

Instantly share code, notes, and snippets.

@ifels
Created August 16, 2014 15:11
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 ifels/5f034af0e1cc114e2ff7 to your computer and use it in GitHub Desktop.
Save ifels/5f034af0e1cc114e2ff7 to your computer and use it in GitHub Desktop.
golang file list
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