Created
July 20, 2020 20:13
-
-
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"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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