diff --git a/src/config.py b/src/config.py
index c865ded27b588fa6de183263d17887870ed6bf66..46e4ad2ea8fbbc27b640268ff20dc904b9c6a3b7 100644
--- a/src/config.py
+++ b/src/config.py
@@ -242,11 +242,13 @@ class Config(SQL):
         file = ""
 
         if os.name == 'posix':
-            file = os.path.expanduser('~') + config_dir + config_file
+            ndir = os.path.expanduser('~') + config_dir
         else:
-            ndir = os.path.expanduser('~') + config_dir.replace("/", "\\")
-            os.makedirs(ndir, exist_ok = True)
-            file = ndir + config_file
+            ndir = os.path.expanduser('~') + config_dir
+            ndir = ndir.replace("/", "\\")
+
+        os.makedirs(ndir, exist_ok = True)
+        file = ndir + config_file
 
         return file
 
diff --git a/src/tools.py b/src/tools.py
index 0e7a48d6e872a164e1f389e450e519f42a43177d..c71c91d199a1bd435596a053610bbcc1b971ddb5 100644
--- a/src/tools.py
+++ b/src/tools.py
@@ -184,6 +184,11 @@ class SQL(object):
     def _init_db_file(self, db):
         exists = Path(db).exists()
 
+        os.makedirs(
+            os.path.dirname(db),
+            exist_ok = True
+        )
+
         self._db = sqlite3.connect(db)
         self._cur = self._db.cursor()