-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathosu_mover.go
80 lines (57 loc) · 1.6 KB
/
osu_mover.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package main
import (
"fmt"
"io"
"io/ioutil"
"log"
"os"
"strings"
"time"
)
func MoveOsuFiles(osuDir string) {
//Setup Logger
filename := fmt.Sprintf("logs/%d-log-osu_move.txt", time.Now().Unix())
file, fileErr := os.OpenFile(filename, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666)
if fileErr != nil {
panic(fileErr)
}
multiWriter := io.MultiWriter(file, os.Stdout)
logger := log.New(multiWriter, ".osz Renamer: ", log.LstdFlags|log.Lshortfile)
songsDirectory, songsDirectoryReadErr := ioutil.ReadDir(osuDir)
if songsDirectoryReadErr != nil {
logger.Fatalf("Failed to read osz directory!")
}
for _, directory := range songsDirectory {
if !directory.IsDir() {
continue
}
folderFiles, folderFilesErr := ioutil.ReadDir(osuDir + "/" + directory.Name())
if folderFilesErr != nil {
logger.Fatalf("Failed to read directory %s", directory.Name())
}
for _, file := range folderFiles {
if file.IsDir() {
continue
}
if !strings.HasSuffix(file.Name(), ".osu") {
continue
}
currentFilename := osuDir + "/" + directory.Name() + "/" + file.Name()
osuFile, osuFileOpenErr := os.Open(currentFilename)
if osuFileOpenErr != nil {
logger.Fatalf("Failed to open file %s", currentFilename)
}
defer osuFile.Close()
out, osuFileCreateErr := os.Create("osus/" + file.Name())
if osuFileCreateErr != nil {
logger.Fatalf("Failed to create file %s", "osus/"+file.Name())
}
defer out.Close()
_, osuFileCopyErr := io.Copy(out, osuFile)
if osuFileCopyErr != nil {
logger.Fatalf("Failed to copy file %s", currentFilename)
}
out.Close()
}
}
}