Skip to content

Instantly share code, notes, and snippets.

@broady
Last active November 20, 2017 06:25
Show Gist options
  • Save broady/49174144d72af9e39f281945fdb12c06 to your computer and use it in GitHub Desktop.
Save broady/49174144d72af9e39f281945fdb12c06 to your computer and use it in GitHub Desktop.
package main
import (
"bytes"
"io/ioutil"
"log"
"os"
"path/filepath"
"time"
)
func main() {
num_files := 0
num_lines := 0
go func() {
t := time.NewTicker(1)
defer t.Stop()
for {
<-t.C
log.Print("progress: files=%s; lines=%s", num_files, num_lines)
}
}()
e := filepath.Walk(os.Args[1], func(path string, info os.FileInfo, err error) error {
go func() error {
num_files++
file, err := ioutil.ReadFile(path)
if err != nil {
return err
}
num_lines += bytes.Count(file, []byte("\n"))
return nil
}()
return nil
})
if e != nil {
print(e.Error())
os.Exit(1)
}
log.Print("files=%s; lines=%s", num_files, num_lines)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment