Last active
November 20, 2017 06:25
-
-
Save broady/49174144d72af9e39f281945fdb12c06 to your computer and use it in GitHub Desktop.
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 ( | |
"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