actually move files using git mv

This commit is contained in:
Jan Bader 2024-10-24 22:33:09 +02:00
parent 65e0b4bc00
commit 3d6dc458ce

23
main.go
View File

@ -1,9 +1,10 @@
package main
import (
"fmt"
"path/filepath"
"fmt"
"io/fs"
"os/exec"
"path/filepath"
"regexp"
)
@ -13,12 +14,22 @@ func main() {
if err != nil {
panic(err)
}
filepath.Walk(dir, func(path string, info fs.FileInfo, err error) error{
filepath.Walk(dir, func(path string, info fs.FileInfo, err error) error {
path = path[len(dir):]
matches := journalRegex.FindStringSubmatch(path)
if len(matches) > 0 {
fmt.Println(path)
fmt.Println(matches[1]+"/"+matches[2]+" - "+ matches[3]+"/"+matches[1]+"-"+matches[2]+"-"+matches[4] + " - " + matches[5])
if len(matches) == 0 {
return nil
}
year, month := matches[1], matches[2]
monthName := matches[3]
day, title := matches[4], matches[5]
newPath := fmt.Sprintf("%s/%s - %s/%s-%s-%s - %s", year, month, monthName, year, month, day, title)
mvCommand := exec.Command("git", "mv", path, newPath)
mvCommand.Dir = dir
output, err := mvCommand.CombinedOutput()
if err != nil {
fmt.Printf("error moving '%s' to '%s':\n%s\n\n", path, newPath, output)
}
return nil
})