-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
53 lines (45 loc) · 1.34 KB
/
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 (
"flag"
"fmt"
"log"
"strings"
"github.com/inhies/go-bytesize"
)
const waitMsg = "Finding duplicate files..."
func main() {
var dir string
var recursive bool
flag.StringVar(&dir, "dir", ".", "Directory to check for duplicates")
flag.BoolVar(&recursive, "r", false, "Check duplicates recursively in all sub-directories")
flag.Parse()
complete := make(chan bool)
defer close(complete)
waitMsgEraseComplete := make(chan bool)
defer close(waitMsgEraseComplete)
go func() {
fmt.Print(waitMsg)
<-complete
fmt.Print(strings.Repeat("\b", len(waitMsg)))
waitMsgEraseComplete <- true
}()
dupeFilesFinder := New(dir, recursive)
dfi, err := dupeFilesFinder.Find()
if err != nil {
complete <- true
<-waitMsgEraseComplete
log.Printf("err: %v", err)
return
}
complete <- true
<-waitMsgEraseComplete
fmt.Println(strings.Repeat("-", 50))
fmt.Printf("Directory : %s\n", dir)
fmt.Printf("Recursive : %v\n", recursive)
fmt.Printf("Total files : %d\n", dfi.Total)
fmt.Printf("Unique files : %d\n", dfi.UniqueFilesCount)
fmt.Printf("Files which are duplicated : %d\n", dfi.DuplicateFilesCount)
sz := bytesize.New(float64(dfi.DuplicateSize))
fmt.Printf("Space taken by the duplicates: %s\n", sz.String())
fmt.Println(strings.Repeat("-", 50))
}