skbio.util.misc.create_dir(dir_name, fail_on_exist=False, handle_errors_externally=False)[source]

Create a directory safely and fail meaningfully


dir_name: string

name of directory to create

fail_on_exist: bool, optional

if true raise an error if dir_name already exists

handle_errors_externally: bool, optional

if True do not raise Errors, but return failure codes. This allows to handle errors locally and e.g. hint the user at a –force_overwrite options.


return_value : int

These values are only returned if no error is raised:

  • 0: directory was safely created
  • 1: directory already existed
  • 2: a file with the same name exists
  • 3: any other unspecified OSError


Depending of how thorough we want to be we could add tests, e.g. for testing actual write permission in an existing dir.


>>> from skbio.util.misc import create_dir
>>> from os.path import exists, join
>>> from tempfile import gettempdir
>>> from os import rmdir
>>> new_dir = join(gettempdir(), 'scikitbio')
>>> create_dir(new_dir)
>>> exists(new_dir)
>>> rmdir(new_dir)