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 package main
import ( import (
"fmt" "fmt"
"path/filepath"
"io/fs" "io/fs"
"os/exec"
"path/filepath"
"regexp" "regexp"
) )
@ -13,12 +14,22 @@ func main() {
if err != nil { if err != nil {
panic(err) 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):] path = path[len(dir):]
matches := journalRegex.FindStringSubmatch(path) matches := journalRegex.FindStringSubmatch(path)
if len(matches) > 0 { if len(matches) == 0 {
fmt.Println(path) return nil
fmt.Println(matches[1]+"/"+matches[2]+" - "+ matches[3]+"/"+matches[1]+"-"+matches[2]+"-"+matches[4] + " - " + matches[5]) }
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 return nil
}) })