A safe function for creating a directory tree.
570
def safe_makedirs(path):
    """"""
    try:
        os.makedirs(path)
    except OSError as err:
        if err.errno == errno.EEXIST:
            if not os.path.isdir(path):
                raise
        else:
            raise
269395
def make_file_system_tree(root_folder, _parent=None):
    
    root_node = Node(os.path.basename(root_folder), _parent)
    root_node.path = root_folder
    for item in os.listdir(root_folder):
        item_path = os.path.join(root_folder, item)
        if os.path.isfile(item_path):
            file_node = Node(os.path.basename(item), root_node)
            file_node.path = item_path
        elif os.path.isdir(item_path):
            #folder_path = os.path.join(root_folder, item)
            make_file_system_tree(item_path, _parent=root_node)
    return root_node
1338191
def ensure_dir(f):
    
    d = os.path.dirname(f)
    if not os.path.exists(d):
        os.makedirs(d)
926308
def safe_mkdir(path):
    
    if os.path.isfile(path):
        die("'{0}' is a regular file: can't overwrite" % path)
    elif os.path.isdir(path):
        info("directory '%s' already exists" % path)
    else:
        info("creating directory '%s'" % path)
        try:
            os.makedirs(path)
        except OSError as e:
            die("""failed to recursively create the directory
%s
%s
  Do you have write permision to that path?
  Or does part of that path already exist as a regular file?""" % (path, e))
    return os.path.abspath(path)
792253
function makedir(p,mode,next){
    if (typeof mode === 'function' || mode === undefined) {
        next = mode;
        mode = 0777 & (~process.umask());
    }
    if (typeof mode === 'string') mode = parseInt(mode, 8);
    p = path.resolve(p);
    // recursively make sure that directory exists.
    //

    var parent = path.dirname(p);
    if(parent){
        fs.exists(p,handleStatforPath(p,mode,parent,next));
    }else{
        // following convention, if the path is actually a dot at this
        // point, prepend the current process root dir and carry on
        // back up the stack.
        //
        if(p === '.'){
            // replace . with rootdir
            p = rootdir;
            // recurse back up with that value
            return next(null,p)
        }

        //
        // not sure what is up.  path.dirname should create '.' for
        // parent of relative path names
        //
        console.log('in make parent dir, no parents left for : '+p+' try prepending the process root dir');
        throw new Error('parent failure ' + p);
    }
    return null;
}
1131759
function buildTree(directory, depth, parentGitignoreList) {
  const files = fs.readdirSync(directory);
  const max_index = files.length - 1
  const color = chalk[colors[depth % colors.length]]
  parentGitignoreList = parentGitignoreList || []
  const gitignoreList = hideFilesInGitIgnore
    ? parentGitignoreList.concat(readGitignore(directory))
    : []

  for (let i = 0; i <= max_index; i++) {
    const file = files[i]
    depths[depth] = max_index - i
    const fullPath = path.resolve(directory, file)
    let printWithoutDescending = false
    let postfix = ''
    let prefix = buildPrefix(depth, i === max_index, directory)
    const stats = fs.statSync(fullPath)
    const isDirectory = stats.isDirectory()
    const size = prettybytes(stats.size)

    if (showTimeStamp) {
      prefix += dateTemplate.render(new Date(stats.mtime))
    }

    if (isDirectory) {
      directoryCount++
    } else {
      fileCount++
      totalFileSize += stats.size
    }

    if (!shouldBeIncluded(file)) {
      continue
    }

    if (hideFilesInGitIgnore) {
      let matchesGitIgnoreEntry = false
      let m = gitignoreList.length
      while (!matchesGitIgnoreEntry && m > 0) {
        matchesGitIgnoreEntry = minimatch(file, gitignoreList[m - 1])
        m--
      }

      if (matchesGitIgnoreEntry) {
        continue
      }
    }

    if (!isDirectory && showOnlyDirectories) {
      continue
    }

    if (isDirectory) {
      if (fileLimit !== Infinity || pruneEmptyDirectories) {
        const dirfiles = fs.readdirSync(fullPath).filter(shouldBeIncluded)
        if (pruneEmptyDirectories && dirfiles.length === 0) {
          continue
        }
        if (dirfiles.length > fileLimit) {
          printWithoutDescending = true
          postfix = ` [${dirfiles.length} entries exceeds filelimit (${fileLimit}), not opening dir]`
        }
      }
    }

    const filename = showFullPath ? color(fullPath.replace(cwd + '/', '')) : color(file)
    const JSXTags = createJSXTags(filename, isDirectory, size, fullPath)

    if (printJSX) {
      output += prefix + JSXTags.open + '\n'
    } else {
      output += prefix + filename + (!isDirectory && showSize ? ` (${size})` : '') + postfix + '\n';
    }
    if (printWithoutDescending) {
      continue
    }
    if (isDirectory && (depth + 1 < maxDepth)) {
      buildTree(path.resolve(directory, file), depth + 1, gitignoreList)
    }
    if (printJSX && JSXTags.close) {
      output += prefix + JSXTags.close + '\n'
    }
    --depths[depth]
  }
}
1310944
def _ensure_tree(path):
    
    try:
        os.makedirs(path)
    except OSError as e:
        if e.errno == errno.EEXIST:
            if not os.path.isdir(path):
                raise
            else:
                return False
        elif e.errno == errno.EISDIR:
            return False
        else:
            raise
    else:
        return True
859956
def tree_walk(cls, directory, tree):
        """"""
        results = []
        dirs = [d for d in tree if d != FILE_MARKER]
        files = tree[FILE_MARKER]
        results.append((directory, dirs, files))
        for d in dirs:
            subdir = os.path.join(directory, d)
            subtree = tree[d]
            results.extend(cls.tree_walk(subdir, subtree))
        return results
210894
def list_to_tree(cls, files):
        """"""

        def attach(branch, trunk):
            """Insert a branch of directories on its trunk."""
            parts = branch.split('/', 1)
            if len(parts) == 1:  # branch is a file
                trunk[FILE_MARKER].append(parts[0])
            else:
                node, others = parts
                if node not in trunk:
                    trunk[node] = defaultdict(dict, ((FILE_MARKER, []), ))
                attach(others, trunk[node])

        tree = defaultdict(dict, ((FILE_MARKER, []), ))
        for line in files:
            attach(line, tree)
        return tree
650499
function _setDirectoryOpen(treeData, path, open) {
        var objectPath = _filePathToObjectPath(treeData, path),
            directory = treeData.getIn(objectPath);

        if (!objectPath) {
            return {
                needsLoading: true,
                treeData: treeData
            };
        }

        if (isFile(directory)) {
            return;
        }

        var alreadyOpen = directory.get("open") === true;

        if ((alreadyOpen && open) || (!alreadyOpen && !open)) {
            return;
        }

        treeData = treeData.updateIn(objectPath, function (directory) {
            if (open) {
                return directory.set("open", true);
            } else {
                return directory.delete("open");
            }
        });

        if (open && (directory.get("children") === null || directory.get("notFullyLoaded"))) {
            return {
                needsLoading: true,
                treeData: treeData
            };
        }
        return {
            needsLoading: false,
            treeData: treeData
        };
    }
1138645
function _closeSubtree(directory) {
        directory = directory.delete("open");

        var children = directory.get("children");
        if (children) {
            children.keySeq().forEach(function (name) {
                var subdir = children.get(name);
                if (!isFile(subdir)) {
                    subdir = _closeSubtree(subdir);
                    children = children.set(name, subdir);
                }
            });
        }

        directory = directory.set("children", children);
        return directory;
    }
929095
def check_and_create_directories(paths):
    
    for path in paths:
        if os.path.exists(path):
            shutil.rmtree(path)
        os.mkdir(path)
448540
def makedirs(d):
    """"""
    if sys.version_info[0] < 3:
        from distutils.dir_util import mkpath
        mkpath(d)
    else:
        os.makedirs(d, exist_ok=True)
646215
def create_directory(directory):
    """"""
    if os.path.exists(directory):
        rmtree(directory)
    os.makedirs(directory)
    return directory
532813
def safe_mkdir_for(path, clean=False):
  
  safe_mkdir(os.path.dirname(path), clean=clean)
459501
def __generate_tree(self, top, src, resources, models, ctrls, views, utils):
        """"""
        res = self.__mkdir(top)
        for fn in (src, models, ctrls, views, utils): res = self.__mkpkg(fn) or res
        res = self.__mkdir(resources) or res
        res = self.__mkdir(os.path.join(resources, "ui", "builder")) or res
        res = self.__mkdir(os.path.join(resources, "ui", "styles")) or res
        res = self.__mkdir(os.path.join(resources, "external")) or res
        return res
350831
function mkdirSyncRecursive(root, chunks, mode) {

  var chunk = chunks.shift();
  if (!chunk) {
    return;
  }
  var root = path.join(root, chunk);

  if (fs.existsSync(root) === true) { // already done
    return mkdirSyncRecursive(root, chunks, mode);
  }
  var err = fs.mkdirSync(root, mode);
  return err ? err : mkdirSyncRecursive(root, chunks, mode); // let's magic
}