Skip to content

Commit

Permalink
create dir if it does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
snbianco committed Jun 11, 2024
1 parent 22a7907 commit 1a69e07
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions astroquery/mast/observations.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
This module contains various methods for querying MAST observations.
"""

from pathlib import Path
import warnings
import time
import os
Expand Down Expand Up @@ -536,8 +537,12 @@ def download_file(self, uri, *, local_path=None, base_url=None, cache=True, clou
filename = os.path.basename(uri)
if not local_path: # local file path is not defined
local_path = filename
elif os.path.isdir(local_path): # local file path is directory
local_path = os.path.join(local_path, filename) # append filename
else:
path = Path(local_path)
if not path.suffix: # local_path is a directory
local_path = path / filename # append filename
if not path.exists(): # create directory if it doesn't exist
path.mkdir(parents=True, exist_ok=True)

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

0 comments on commit 1a69e07

Please sign in to comment.