-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
53 lines (45 loc) · 843 Bytes
/
main.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
package main
import (
"fmt"
"io/ioutil"
"os"
"sync"
)
var sizes = make(chan int64)
const PATH_SCAN = "/Users/estcele/Downloads/"
// var files = make(map[string]int64)
var files sync.Map
func main() {
// files := sync.Map{}
fis, err := ioutil.ReadDir(PATH_SCAN)
if err != nil {
fmt.Errorf(err.Error())
return
}
wg := sync.WaitGroup{}
for _, fi := range fis {
wg.Add(1)
go func(fi os.FileInfo) {
defer wg.Done()
if !fi.IsDir() {
// files[fi.Name()] = fi.Size()
files.Store(fi.Name(), fi.Size())
sizes <- fi.Size()
}
}(fi)
}
go func() {
wg.Wait()
close(sizes)
}()
var total int64
for size := range sizes {
total += size
}
fmt.Println("File Name Size")
files.Range(func(key, value any) bool {
fmt.Printf("%s\t%d\n", key, value)
return true
})
fmt.Printf("Total\t%d\n", total)
}