Skip to content

Commit

Permalink
Merge pull request #1 from sectioneight/support-multiple-paths
Browse files Browse the repository at this point in the history
Support multiple paths on the command line
  • Loading branch information
egonelbre committed Jan 6, 2016
2 parents 4862494 + 32aa8de commit 5a58813
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ func ShouldExamine(ext string) bool {
func main() {
flag.Parse()

path := flag.Arg(0)
if path == "" {
path = "."
paths := flag.Args()
if len(paths) == 0 {
paths = []string{"."}
}

if *exts != "" {
Expand All @@ -47,7 +47,7 @@ func main() {

work := make(chan string, 100)
results := make(chan CountByExt, *procs)
go IterateDir(path, work)
go IterateDir(work, paths...)

for i := 0; i < *procs; i++ {
go FileWorker(work, results, &progress)
Expand Down Expand Up @@ -102,7 +102,7 @@ func FileWorker(files chan string, result chan CountByExt, progress *int64) {
}
}

func IterateDir(root string, work chan string) {
func IterateDir(work chan string, roots ...string) {
walk := func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
Expand Down Expand Up @@ -130,9 +130,11 @@ func IterateDir(root string, work chan string) {
return nil
}

err := filepath.Walk(root, walk)
if err != nil {
log.Println(err)
for _, root := range roots {
err := filepath.Walk(root, walk)
if err != nil {
log.Println(err)
}
}

close(work)
Expand Down

0 comments on commit 5a58813

Please sign in to comment.