-
Notifications
You must be signed in to change notification settings - Fork 0
/
blast-em-all.go
55 lines (46 loc) · 1.06 KB
/
blast-em-all.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package diskstuff
/* Copyright © 2022 sparksb -- MIT (see LICENSE file) */
/* Copyright © 2022 Brian C Sparks <briancsparks@gmail.com> -- MIT (see LICENSE file) */
import (
"fmt"
"os"
"path"
)
func Blast(folder string) {
var count int
if len(folder) == 0 {
folder = "."
}
count = countGoFiles(folder)
fmt.Printf("Count: %d\n", count)
fmt.Printf("Count2: %d\n", countGoFiles2(folder, 0))
}
func countGoFiles2(folder string, count int) int {
files, err := os.ReadDir(folder)
if err != nil {
fmt.Printf("Error in countGoFiles: %v\n", err)
return count
}
for _, file := range files {
if file.IsDir() {
count = countGoFiles2(folder+"/"+file.Name(), count)
}
if path.Ext(file.Name()) == ".go" {
count += 1
}
}
return count
}
func countGoFiles(folder string) (count int) {
files, err := os.ReadDir(folder)
if err != nil {
fmt.Printf("Error in countGoFiles: %v\n", err)
return 0
}
for _, file := range files {
if path.Ext(file.Name()) == ".go" {
count += 1
}
}
return count
}