This commit is contained in:
Jan Bader
2024-10-23 22:27:45 +02:00
commit 65e0b4bc00
2 changed files with 28 additions and 0 deletions

3
go.mod Normal file
View File

@ -0,0 +1,3 @@
module git.javil.eu/jacob1123/rename-journal
go 1.22.7

25
main.go Normal file
View File

@ -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
})
}