-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
54 lines (47 loc) · 1.49 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
54
package main
import (
"flag"
"log"
"strings"
"sync"
"github.com/sauercrowd/image-sorter/pkg/finder"
"github.com/sauercrowd/image-sorter/pkg/mover"
)
func main() {
f := parseFlags()
ch := make(chan string)
if f.threads < 2 {
f.threads = 2
}
var wg sync.WaitGroup
wg.Add(f.threads - 1)
for i := 0; i < f.threads-1; i++ {
go mover.Worker(ch, f.outDir, &wg, f.regex, f.placeholder, f.exif)
}
wildcard := ""
for i := 0; i < len(f.placeholder); i++ {
wildcard += "."
}
finderRegex := strings.Replace(f.regex, f.placeholder, wildcard, 1)
err := finder.Worker(ch, f.inDir, finderRegex)
if err != nil {
log.Fatalf("Error while finding files: %v", err)
}
wg.Wait()
}
type flags struct {
inDir, outDir, regex, placeholder string
fileTypes []string
threads int
exif bool
}
func parseFlags() flags {
in := flag.String("in", "", "Directory which should be sorted")
out := flag.String("out", "", "Directory where sorted stuff should be moved")
regx := flag.String("regex", ".*", "pattern of files which should be matched")
sep := flag.String("placeholder", "XXXX", "The placeholder for the pattern")
threads := flag.Int("n", 2, "number of threads to use, mininum 2")
useExif := flag.Bool("exif", false, "if true, uses exif data to get year and move it into a folder according to its year")
flag.Parse()
return flags{inDir: *in, outDir: *out, regex: *regx, placeholder: *sep, threads: *threads, exif: *useExif}
}