diff options
author | Ben Sima <ben@bsima.me> | 2018-06-13 21:36:56 -0700 |
---|---|---|
committer | Ben Sima <ben@bsima.me> | 2018-06-13 21:36:56 -0700 |
commit | 77c9a177b2b595d4ce25095b58e2388fe33cc97a (patch) | |
tree | 0853d5c92d67538760005b9c4635a90115bd7ba4 /fix-journal-filenames.py |
init
Diffstat (limited to 'fix-journal-filenames.py')
-rwxr-xr-x | fix-journal-filenames.py | 21 |
1 files changed, 21 insertions, 0 deletions
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) + ) |