Skip to content

Commit 584a1ec

Browse files
committed
create dir if it does not exist
1 parent ac0cbd7 commit 584a1ec

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

astroquery/mast/observations.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
This module contains various methods for querying MAST observations.
77
"""
88

9+
from pathlib import Path
910
import warnings
1011
import time
1112
import os
@@ -536,8 +537,12 @@ def download_file(self, uri, *, local_path=None, base_url=None, cache=True, clou
536537
filename = os.path.basename(uri)
537538
if not local_path: # local file path is not defined
538539
local_path = filename
539-
elif os.path.isdir(local_path): # local file path is directory
540-
local_path = os.path.join(local_path, filename) # append filename
540+
else:
541+
path = Path(local_path)
542+
if not path.suffix: # local_path is a directory
543+
local_path = path / filename # append filename
544+
if not path.exists(): # create directory if it doesn't exist
545+
path.mkdir(parents=True, exist_ok=True)
541546

542547
# recreate the data_product key for cloud connection check
543548
data_product = {'dataURI': uri}

0 commit comments

Comments
 (0)