Skip to content

Instantly share code, notes, and snippets.

@roustem
Created October 14, 2021 22:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roustem/b8c9d2dc3c6aa1829cb507c6c5efcd77 to your computer and use it in GitHub Desktop.
Save roustem/b8c9d2dc3c6aa1829cb507c6c5efcd77 to your computer and use it in GitHub Desktop.
Rename markdown files exported from Roam to YYYY-MM-DD format for logseq
import os
import re
date_re = re.compile("(\w+) (\d+)(rd|th|st|nd), 2021.md")
month_to_number = {
'January': "01",
'February': "02",
'March': "03",
'April': "04",
'May': "05",
'June': "06",
'July': "07",
'August': "08",
'September': "09",
'October': "10",
'November': "11",
'December': "12"}
for root, dirs, files in os.walk("./"):
for filename in files:
if filename.endswith(".md"):
new_filename = filename
m = date_re.match(filename)
if m:
new_filename = "2021-" + \
month_to_number[m.group(1)] + "-" + \
m.group(2).rjust(2, "0") + ".md"
os.rename(os.path.join(root, filename),
os.path.join(root, new_filename))
# new_contents = re.sub(
# "(202\d)(\d\d)(\d\d)", "\g<1>-\g<2>-\g<3>", contents)
# if new_contents != contents or new_filename != filename:
# print(filename + " => " + new_filename)
# print(new_contents)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment