package main
import (
"fmt"
"io/ioutil"
"log"
"strings"
)
func countLines(filename string) (int, error) {
content, err := ioutil.ReadFile(filename)
if err != nil {
return 0, err
}
lines := strings.Split(string(content), "\n")
return len(lines), nil
}
func main() {
files, err := ioutil.ReadDir(".")
if err != nil {
log.Fatal(err)
}
for _, file := range files {
if file.IsDir() {
continue
}
filename := file.Name()
lines, err := countLines(filename)
if err != nil {
log.Printf("Error reading %s: %v\n", filename, err)
continue
}
fmt.Printf("%s: %d lines\n", filename, lines)
}
}