Skip to content

Instantly share code, notes, and snippets.

@Catbuttes
Created July 20, 2020 20:13
Show Gist options
  • Save Catbuttes/bacdf2e79a503921f625181039e9adaf to your computer and use it in GitHub Desktop.
Save Catbuttes/bacdf2e79a503921f625181039e9adaf to your computer and use it in GitHub Desktop.
A quick and dirty script to rename files from the format "Sunday 25th February 2018.md" to the format "2018-02-25.md"
import datetime
import os
files = os.listdir("journal/2019")
for file in files:
if file == "images":
continue
a = file.replace("th", "")
a = a.replace(".md", "")
a = a.replace("st", "")
a = a.replace("rd ", " ")
a = a.replace("nd ", " ")
d = datetime.datetime.strptime(a, "%A %d %B %Y")
print(file)
print(d.strftime("%Y-%m-%d.md"))
os.rename("journal/2019/"+file, "journal/2019/"+d.strftime("%Y-%m-%d.md"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment