-
Notifications
You must be signed in to change notification settings - Fork 0
/
zfix.go
48 lines (35 loc) · 879 Bytes
/
zfix.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
package main
import (
"fmt"
"io/ioutil"
"log"
"path/filepath"
"strings"
)
func main() {
var photoFiles []string
var e error
src6 := "NIKON Z 6_2"
dst6 := "NIKON Z 6 " // two spaces in the end are intentional
// or:
src7 := "NIKON Z 7_2"
dst7 := "NIKON Z 7 " // two spaces in the end are intentional
photoFiles, e = filepath.Glob("*.[nN][eE][fF]")
checkError(e)
for _, pFile := range photoFiles {
fmt.Print("Processing: " + pFile)
fileContents, errRead := ioutil.ReadFile(pFile)
checkError(errRead)
newContents := strings.Replace(string(fileContents), src6, dst6, -1)
newContents = strings.Replace(string(newContents), src7, dst7, -1)
errWrite := ioutil.WriteFile(pFile, []byte(newContents), 0)
checkError(errWrite)
fmt.Println(" - 100%")
}
fmt.Println("Done!")
}
func checkError(err error) {
if err != nil {
log.Fatal(err)
}
}