def make_sure_dir_exists(dir_, create_subfolders=False):
assert isinstance(dir_, (str, _oldstr))<EOL>assert isinstance(create_subfolders, bool)<EOL>try:<EOL><INDENT>if create_subfolders:<EOL><INDENT>os.makedirs(dir_)<EOL><DEDENT>else:<EOL><INDENT>os.mkdir(dir_)<EOL><DEDENT><DEDENT>except OSError as exception:<EOL><INDENT>if exception.errno != errno.EEXIST:<EOL><INDENT>raise<EOL><DEDENT><DEDENT>
Ensures that a directory exists.

    Adapted from StackOverflow users "Bengt" and "Heikki Toivonen"
    (http://stackoverflow.com/a/5032238).

    Parameters
    ----------
    dir_: str
        The directory path.
    create_subfolders: bool, optional
        Whether to create any inexistent subfolders. [False]

    Returns
    -------
    None

    Raises
    ------
    OSError
        If a file system error occurs.