-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
63 lines (54 loc) · 1.4 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
55
56
57
58
59
60
61
62
63
package main
import (
"bufio"
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"strings"
)
func main() {
var inputFolderPath, inputFilePath string
var mobijakeList []string
flag.StringVar(&inputFolderPath, "i", "", "Path to folder with files")
flag.StringVar(&inputFilePath, "a", "", "Path to file with archive downloads")
flag.Parse()
if inputFolderPath == "" {
fmt.Println("Input folder with mobijake files has to be specified i.e. with -i path/to/folder")
return
}
if inputFilePath == "" {
fmt.Println("Input file with archive download has to be specified i.e. with -a path/to/file")
return
}
inFile, _ := os.Open(inputFilePath)
defer inFile.Close()
scanner := bufio.NewScanner(inFile)
scanner.Split(bufio.ScanLines)
files, err := ioutil.ReadDir(inputFolderPath)
if err != nil {
log.Fatal(err)
}
for scanner.Scan() {
mobijake := strings.Split(scanner.Text(), " ")[1]
mobijakeList = append(mobijakeList, mobijake)
}
for _, file := range files {
fileName := file.Name()
replace(mobijakeList, fileName, inputFolderPath)
}
}
func replace(mobijakes []string, fileName string, folder string) {
for _, mj := range mobijakes {
if strings.Contains(fileName, mj) {
newName := strings.Replace(fileName, "-"+mj, "", -1)
originalPath := folder + "/" + fileName
newPath := folder + "/" + newName
err := os.Rename(originalPath, newPath)
if err != nil {
log.Fatal(err)
}
}
}
}