-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathosz_renamer.go
51 lines (38 loc) · 1004 Bytes
/
osz_renamer.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
package main
import (
"fmt"
"io"
"io/ioutil"
"log"
"os"
"strings"
"time"
)
func RenameOszs(oszDir string) {
//Setup Logger
filename := fmt.Sprintf("logs/%d-log-osz_rename.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)
oszDirectory, oszDirectoryReadErr := ioutil.ReadDir(oszDir)
if oszDirectoryReadErr != nil {
logger.Fatalf("Failed to read osz directory!")
}
for _, file := range oszDirectory {
if file.IsDir() {
continue
}
if !strings.HasSuffix(file.Name(), ".osz") {
continue
}
oldName := oszDir + "/" + file.Name()
newName := oszDir + "/" + strings.Split(file.Name(), " ")[0] + ".osz"
renameErr := os.Rename(oldName, newName)
if renameErr != nil {
logger.Printf("Failed to rename %s to %s", oldName, newName)
}
}
}