EdgeTA / utils /common /file.py
LINC-BIT's picture
Upload 1912 files
b84549f verified
raw
history blame contribute delete
435 Bytes
import os
import pathlib
def ensure_dir(file_path: str):
"""Create it if the directory of :attr:`file_path` is not existed.
Args:
file_path (str): Target file path.
"""
if isinstance(file_path, pathlib.Path):
file_path = str(file_path)
if not os.path.isdir(file_path):
file_path = os.path.dirname(file_path)
if not os.path.exists(file_path):
os.makedirs(file_path)