mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-06-28 21:46:13 +02:00
Create directory if it doesn't exist (#963)
* create dir if it doesn't exist * switch order of print and creation * makedirs instead of mkdir and stderr printing * add test * black reformatting
This commit is contained in:
parent
ca73c74a8e
commit
74724b2185
3 changed files with 14 additions and 2 deletions
|
@ -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):
|
||||
os.makedirs(dirname)
|
||||
print(f"[Directory {dirname} created]", file=sys.stderr)
|
||||
self.create_file(filename)
|
||||
print(f"[Journal '{self.name}' created at {filename}]", file=sys.stderr)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue