diff --git a/main.go b/main.go index d9f938e..b6ef912 100644 --- a/main.go +++ b/main.go @@ -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 })