Reduce callback to reduce the list of directories
@param {object} prev
@param {array} dir
326755
function createListOfDirectories(prev, dir) {
  return {
    ...prev,
    [dir.split(path.sep).pop()]: dir,
  }
}
778625
function dirExists(dir, cb) {
  var fsExists = fs.exists || path.exists;
  fsExists(dir, function (exists) {
    if (!exists) {
      return cb(false);
    }
    fs.stat(dir, function (err, stat) {
      if (err) {
        return cb(false);
      }
      return cb(stat.isDirectory());
    });
  });
}
159623
async function (directory, filesInSassTree, exclusions) {
  const filesInDirectory = (await recursive(directory));

  const unusedFiles = filesInDirectory
    .filter((file) => isUnused(file, filesInSassTree, exclusions));

  return unusedFiles;
}
374706
function stringifyDirection(dir, oldStyle) {
		var reNewStyle = /^to\s/;
		var keys = Object.keys(directions).filter(function(k) {
			var hasPrefix = reNewStyle.test(k);
			return oldStyle ? !hasPrefix : hasPrefix;
		});

		for (var i = 0; i < keys.length; i++) {
			if (directions[keys[i]] == dir) {
				return keys[i];
			}
		}

		if (oldStyle) {
			dir = (dir + 270) % 360;
		}

		return dir + 'deg';
	}
1013988
function(replace, count, callback) {
    return pathmap.replace(
      pathmap.dirname(this, count), replace, callback);
  }
159023
function writeDirectories(result) {
  var deferred = q.defer();
  util.mkdir(result.root)
    .then(function() {return util.mkdir(result.template);})
    .then(function() {return util.mkdir(result.data);})
    .then(function() {return util.mkdir(result.output);})
    .then(function() {return util.mkdir(result.js);})
    .then(function() {return util.mkdir(result.css);})
    .fail(function(err) {
      deferred.reject(new Error(err));
    })
    .done(function(result) {
      deferred.resolve();
    });
  return deferred.promise;
}
787217
function (dir, filelist, ext, currentBundleOptions) {
    var path = path || require('path');
    var fs = fs || require('fs');
    var files = fs.readdirSync(dir);
    filelist = filelist || [];
    files.forEach(function (file) {
        if (fs.statSync(path.join(dir, file)).isDirectory()) {
            filelist = walkSync(path.join(dir, file), filelist, ext, currentBundleOptions);
        }
        else {
            if (file.match(new RegExp("." + ext + "$")) && !isExcluded(file, currentBundleOptions))
                filelist.push(path.join(dir, file));
        }
    });
    return filelist;
}
343321
function _emptyDirectoryProm (directory) {

			return new Promise((resolve, reject) => {

				readdir(directory, (err, files) => {
					return err ? reject(err) : resolve(files);
				});

			}).then((files) => {

				const result = [];

					for (let i = 0; i < files.length; ++i) {
						result.push(join(directory, files[i]));
					}

				return Promise.resolve(result);

			}).then((files) => {
				return files.length ? _removeDirectoryContentProm(files) : Promise.resolve();
			});

		}
412808
function deleteSvnFolders(dir) {
    var contents = fs.readdirSync(dir);
    contents.forEach(function(entry) {
        var fullpath = path.join(dir, entry);
        if (fs.statSync(fullpath).isDirectory()) {
            if (entry == '.svn') {
                shell.rm('-rf', fullpath);
            } else module.exports.deleteSvnFolders(fullpath);
        }
    });
}
406574
function _recursiveMkDir(dir) {
  if (!fs.existsSync(dir)) {
    _recursiveMkDir(path.dirname(dir));
    fs.mkdirSync(dir);
  }
}
1092847
static function recursiveList( $dir, $path, &$fileList )
    {
        if ( $handle = @opendir( $dir ) )
        {
            while ( ( $file = readdir( $handle ) ) !== false )
            {
                if ( ( $file == "." ) || ( $file == ".." ) )
                {
                    continue;
                }
                if ( is_dir( $dir . '/' . $file ) )
                {
                    $fileList[] = array( 'path' => $path, 'name' => $file, 'type' => 'dir' );
                    eZDir::recursiveList( $dir . '/' . $file, $path . '/' . $file, $fileList );
                }
                else
                {
                    $fileList[] = array( 'path' => $path, 'name' => $file, 'type' => 'file'  );
                }
            }
            @closedir( $handle );
        }
    }
216982
function findDir(dirList, ifCb, elseCb) {
  async.detect(dirList, dirExists, function (dir) {
    if (dir) {
      ifCb(dir);
    } else {
      elseCb();
    }
  });
}
722733
function _cmdRemove(extensionDir, callback, pCallback) {
    fs.remove(extensionDir, function (err) {
        if (err) {
            callback(err);
        } else {
            callback(null);
        }
    });
}
896460
function mkdirs(dir) {
  return new Promise((resolve, reject) => {
    FS.ensureDir(dir, err => {
      err ? reject(err) : resolve(dir);
    })
  });
}
1299167
function dirsExist(dirs) {
  if (0 === dirs.length) {
    return new Promise((resolve) => {
      resolve({});
    });
  }

  // Group dirs by '/' count
  const dirsByDepth = dirs.reduce(function(prev, curItem) {
    const depth = curItem.split(path.sep).length;
    (prev[depth] = prev[depth] || []).push(curItem);

    return prev;
  }, {});

  // Extract min depth dirs
  const allDepths = Object.keys(dirsByDepth).map(Number);
  const currDepth = Math.min(...allDepths);
  const currDirs = dirsByDepth[currDepth];

  // Prepare result object
  const result = dirs.reduce(function(prev, item) {
    prev[item] = null;

    return prev;
  }, {});

  // Check if min depth dirs exist
  return stupidDirsExist(currDirs).then((localResult) => {
    Object.keys(result).forEach((dir) => {
      if (null !== result[dir]) {
        return;
      }

      Object.keys(localResult).forEach((localDir) => {
        // Transfer local check result to global "as is"
        result[localDir] = localResult[localDir];

        // Additionally check if we can mark more deeper directories
        // as non-existing
        if (false === localResult[localDir] &&
          dir.slice(0, localDir.length + 1) === localDir + path.sep) {
          result[dir] = false;
        }
      });
    });

    // Extract not checked dirs
    const restDirs = dirs.filter((dir) => {
      return null === result[dir];
    });

    return dirsExist(restDirs);
  }).then((finalResult) => {
    // Transfer local check result to global "as is"
    Object.keys(finalResult).forEach((finalDir) => {
      result[finalDir] = finalResult[finalDir];
    });

    return result;
  });
}
203563
function(dir, files){		
		fs.readdirSync(dir).forEach(function(file){
			try{
				var current = path.join(dir, file);
				var stat = fs.statSync(current);
				if (stat && stat.isDirectory()) {
					getAllFiles(current, files);
				}else {
				    files.push(current);
				}
			}catch(e){
				console.error(e);
			}
        });
	}
511436
def delete(self, key, dir=False, recursive=False,
               prev_value=None, prev_index=None, timeout=None):
        """"""
        url = self.make_key_url(key)
        params = self.build_args({
            'dir': (bool, dir or None),
            'recursive': (bool, recursive or None),
            'prevValue': (six.text_type, prev_value),
            'prevIndex': (int, prev_index),
        })
        try:
            res = self.session.delete(url, params=params, timeout=timeout)
        except:
            self.erred()
        return self.wrap_response(res)