commit 65e0b4bc0035d9ea66fa51156fa36d6507d804a9 Author: Jan Bader Date: Wed Oct 23 22:27:45 2024 +0200 Initial diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..e6410d2 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module git.javil.eu/jacob1123/rename-journal + +go 1.22.7 diff --git a/main.go b/main.go new file mode 100644 index 0000000..d9f938e --- /dev/null +++ b/main.go @@ -0,0 +1,25 @@ +package main + +import ( +"fmt" + "path/filepath" + "io/fs" + "regexp" +) + +func main() { + dir := "/home/jacob/Notes/Journal/" + journalRegex, err := regexp.Compile("^(\\d\\d\\d\\d)/(\\d\\d) - ([^/]*)/(\\d\\d) - ([^/]*)$") + if err != nil { + panic(err) + } + 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]) + } + return nil + }) +}