From 16dd596bb23be4a5875b9ce0e5eb5664e0776a40 Mon Sep 17 00:00:00 2001 From: Eshan Ramesh Date: Mon, 25 May 2020 23:41:13 -0400 Subject: [PATCH] create dir if it doesn't exist --- jrnl/EncryptedJournal.py | 5 ++++- jrnl/Journal.py | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/jrnl/EncryptedJournal.py b/jrnl/EncryptedJournal.py index 2a6df460..6121f304 100644 --- a/jrnl/EncryptedJournal.py +++ b/jrnl/EncryptedJournal.py @@ -40,8 +40,11 @@ class EncryptedJournal(Journal): """Opens the journal file defined in the config and parses it into a list of Entries. Entries have the form (date, title, body).""" filename = filename or self.config["journal"] - + dirname = os.path.dirname(filename) if not os.path.exists(filename): + if not os.path.isdir(dirname): + print(f"[Directory {dirname} created]") + os.mkdir(dirname) self.create_file(filename) self.password = util.create_password(self.name) print( diff --git a/jrnl/Journal.py b/jrnl/Journal.py index 23fa80a0..45596192 100644 --- a/jrnl/Journal.py +++ b/jrnl/Journal.py @@ -74,8 +74,11 @@ class Journal: """Opens the journal file defined in the config and parses it into a list of Entries. Entries have the form (date, title, body).""" filename = filename or self.config["journal"] - + dirname = os.path.dirname(filename) if not os.path.exists(filename): + if not os.path.isdir(dirname): + print(f"[Directory {dirname} created]") + os.mkdir(dirname) self.create_file(filename) print(f"[Journal '{self.name}' created at {filename}]", file=sys.stderr)