From 77c9a177b2b595d4ce25095b58e2388fe33cc97a Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Wed, 13 Jun 2018 21:36:56 -0700 Subject: init --- fix-journal-filenames.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100755 fix-journal-filenames.py (limited to 'fix-journal-filenames.py') diff --git a/fix-journal-filenames.py b/fix-journal-filenames.py new file mode 100755 index 0000000..5784f40 --- /dev/null +++ b/fix-journal-filenames.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python3 + +import os +import re + +year_re = r"(^\d{4})\d{2}\d{2}$" +month_re = r"^\d{4}(\d{2})\d{2}$" +day_re = r"^\d{4}\d{2}(\d{2}$)" + +files = os.listdir(os.path.expanduser("~/me/journal")) +for f in files: + print("working: ", f) + if '.' in f: + continue + year = re.findall(year_re, f)[0] + month = re.findall(month_re, f)[0] + day = re.findall(day_re, f)[0] + os.rename( + "/home/ben/me/journal/{0}".format(f), + "/home/ben/me/journal/{0}.{1}.{2}".format(year, month, day) + ) -- cgit v1.2.3