Like fs.readdir(), but performs fs.stat() for each file in order to add a '/' to directories
557892
function readdir( dir ) {
	var promise = new Promise() ;

	if ( dir[ dir.length - 1 ] !== '/' ) { dir += '/' ; }

	fs.readdir( dir , ( error , files ) => {

		if ( error ) { promise.reject( error ) ; return ; }

		Promise.map( files , file => {
			return new Promise( ( resolve , reject ) => {
				fs.lstat( dir + file , ( error_ , stats ) => {
					if ( error_ ) { reject( error_ ) ; return ; }
					if ( stats.isDirectory() ) { file += '/' ; }
					resolve( file ) ;
				} ) ;
			} ) ;
		} )
			.toPromise( promise ) ;
	} ) ;

	return promise ;
}
375555
function isDirectory(filePath) {
  if (!isExist(filePath)) return false;
  try {
    const stat = fs.statSync(filePath);
    return stat.isDirectory();
  } catch (e) {
    return false;
  }
}
955903
function getstat (dpath, _files, cb) {
    ;(function loop (index) {
      if (index == _files.length) return cb()
      var fpath = path.join(dpath, _files[index])
      fs.stat(fpath, function (err, stats) {
        if (err) return cb(err)
        if (stats.isDirectory()) {
          dirs.push(fpath)
        } else {
          files.push(fpath)
        }
        loop(++index)
      })
    }(0))
  }
1041524
function isDirectory(filePath, callback) {
  try {
    fs.stat(filePath, function (err, data) {
      if (err) {
        callback(null, false);
      } else {
        callback(null, data.isDirectory());
      }
    });
  } catch (e) {
    callback(null, false);
  }
}
852456
function readDir(dir) {
    var files = [];
    var root = fs.readdirSync(dir);
    var readMe = false;
    for (var i = 0; i < root.length; i++) {
        var filePath = dir + '/' + root[i];
        var stat = fs.statSync(filePath);
        //console.log(filePath,dir);
        filePath = path.relative(dir, filePath);
        if (stat && stat.isDirectory()) {
            files.push({
                dir: true,
                path: filePath
            });
        } else {
            files.push({
                dir: false,
                path: filePath
            });
        }

        // check if it is readme
        if(root[i].toLowerCase() === 'readme.md'){
            readMe = dir + '/' + root[i];
        }
    }
    return {
        files: files,
        readMe : readMe
    };
}
611669
function readDir(err, files) {
  if (err) {
    internalServerError.call(this, err);
  } else {
    var dirName = decodeURIComponent(
      getCurrentPathName(this)
    );
    this.output.push(
      "<!doctype html>",
      "<html>",
        "<head>",
          "<title>Index of ", dirName, "</title>",
          '<meta name="viewport" content="',
            'width=device-width,',
            'initial-scale=1.0,',
            'maximum-scale=1.0,',
            'user-scalable=no',
          '"/>',
          '<meta name="generator" content="polpetta" />',
        "</head>",
        "<body>",
          "<strong>Index of " + dirName + "</strong>",
          "<ul>"
    );
    if (dirName != WEB_SEP) {
      this.output.push(
        '<li><a href="..">..</a></li>'
      );
    }
    files.forEach(readDir.forEach, this.output);
    this.output.push(
          "</ul>",
        "</body>",
      "</html>"
    );
    this.output.flush(200, "text/html", "utf-8");
  }
}
314813
function tryFile(directories, filename) {
	return firstResult(directories, dir => {
		const filepath = path.resolve(dir, filename);
		return fs.existsSync(filepath) ? filepath : undefined;
	});
}
1078817
function readDirSync (dir, allFiles = []) {
  const files = fs.readdirSync(dir).map(f => join(dir, f))
  allFiles.push(...files)
  files.forEach(f => {
    fs.statSync(f).isDirectory() && readDirSync(f, allFiles)
  })
  return allFiles
}
1339431
function stat(dir) {
    return new Promise(resolve => {
        fs.lstat(dir, (err, stats) => resolve(err ? null : stats));
    });
}
188806
function fsReaddirSync(root, files, fp) {
  if (typeof root !== 'string') {
    throw new TypeError('fsReaddir.sync: expect `root` to be string');
  }

  fp = fp || '';
  files = files || [];

  var dir = path.join(root, fp);
  if (fs.statSync(dir).isDirectory()) {
    fs.readdirSync(dir).forEach(function(name) {
      fsReaddirSync(root, files, path.join(dir, name));
    });
  } else {
    files.push(fp);
  }

  return files;
}
621367
function readdir (archive, name, opts, cb) {
  if (typeof opts === 'function') {
    cb = opts
    opts = {}
  }
  opts = opts || {}

  return maybe(cb, async function () {
    // options
    var recursive = (opts && !!opts.recursive)

    // run first readdir
    var promise = new Promise((resolve, reject) => {
      archive.readdir(name, (err, names) => {
        if (err) reject(toBeakerError(err, 'readdir'))
        else resolve(names)
      })
    })
    var results = await promise

    // recurse if requested
    if (recursive) {
      var rootPath = name
      const readdirSafe = name => new Promise(resolve => {
        archive.readdir(name, (_, names) => resolve(names || []))
      })
      const recurse = async function (names, parentPath) {
        await Promise.all(names.map(async function (name) {
          var thisPath = path.join(parentPath, name)
          var subnames = await readdirSafe(thisPath)
          await recurse(subnames, thisPath)
          results = results.concat(subnames.map(subname => normalize(rootPath, thisPath, subname)))
        }))
      }
      await recurse(results, name)
    }
    return results
  })
}
692681
async function mkdirp(dir, mode=0o777, recursive=false){
    
    // stats command executable ? dir/file exists
    const stats = await _statx(dir);

    // dir already exists ?
    if (stats){
        // check if its a directory
        if (!stats.isDirectory()){
            throw new Error('Requested directory <' + dir  + '> already exists and is not of type directory');
        }

        // check mode
        if (stats.mode !== mode){
            await _fs.chmod(dir, mode);
        }

    // create it recursivly
    }else if (recursive){
        // absolute or relative path ? make it absolute
        // split into components
        const dirComponents = _path.parse(_path.resolve(dir));

        // get root dir (posix + windows)
        const rootDir = dirComponents.root;

        // extract dir (without root)
        const dirRelativePath = _path.join(dirComponents.dir, dirComponents.base).substring(rootDir.length);

        // split into parts
        const subdirs = dirRelativePath.split(_path.sep);

        // minimum of 1 segement required - this function does not create directories within filesystem root
        if (subdirs.length < 2){
            throw new Error('Recursive mkdir does not create directories within filesystem root!');
        }

        // build initial directory
        let dyndir = _path.join(rootDir, subdirs.shift());

        // iterate over path
        while (subdirs.length > 0){

            // append part
            dyndir = _path.join(dyndir, subdirs.shift());

            // stats command executable ? dir/file exists
            const cstats = await _statx(dyndir);

            // dir already exists ?
            if (cstats){
                // check if its a directory
                if (!cstats.isDirectory()){
                    throw new Error('Requested path <' + dyndir  + '> already exists and not of type directory');
                }
            
            // create directory
            }else{
                await _fs.mkdir(dyndir, mode);
            }
        }

    // just create top level
    }else{
        await _fs.mkdir(dir, mode);
    }
}
632866
function(next) {
          async.map([src,dest], function(path, done) {
            fs.stat(path, function(err, stat) {
              done(null, stat); // Ignore error
            });
          },
          function(err, results) {
            statSrc  = results[0];
            statDest = results[1];
            if(!statSrc) {
              // src is needed
              next(new Error('File not found: ' + src));
            }
            // Ignore anything that is not directory or file
            if(!(statSrc.isFile() || statSrc.isDirectory())) {
              grunt.verbose.writeln('  Ignore:'+' Source is not a file or a directory.'.grey);
              return done(null, false);
            }

            // Add stat to options for user defined transform & process
            options.statSrc  = statSrc;
            options.statDest = statDest;

            next();
          });
        }
666450
function load(dirPath) {

    findFiles(dirPath, function(filePath){
        collection.push( require(filePath) );
    })

    function findFiles(dirPath, callback){
        fs.readdir(dirPath, function(err, files) {
            files.forEach(function(file){
                fs.stat(dirPath + '/' + file, function(err, stats) {
                    if(stats.isFile()) {
                        callback(dirPath + '/' + file);
                    }
                    if(stats.isDirectory()) {
                        getDirectoryFiles(dirPath + '/' + file, callback);
                    }
                });
            });
        });
    }
}
1127640
function mkdir(dir) {
  return new Promise((resolve, reject) => {
    fs.lstat(dir, (err, stats) => {
      // Resolve, when already is directory
      if (!err) return stats.isDirectory() ? resolve() : reject(new Error(`${dir} is not a direcotry.`));
      // Try to create directory
      fs.mkdir(dir, (err) => {
        err ? reject(err) : resolve();
      });
    })
  })
}
686198
function readDirAndStat (inputPath, cb) {

    if (typeof inputPath === "function") {
        cb = inputPath;
        inputPath = process.cwd();
    }

    fs.readdir(inputPath, (err, res) => {
        if (err) { return cb(err); }
        sameTime(bindy(res, (c, done) => {
            let fullPath = path.join(inputPath, c);
            fs.stat(fullPath, (err, stat) => {
                if (err) { return done(err); }
                done(null, {
                    path: fullPath
                  , stat: stat
                });
            });
        }), cb);
    });
}
375251
function isDir(p) {
    if (!fs.existsSync(p)) {
        return false;
    }
    try {
        let stats = fs.statSync(p);
        return stats.isDirectory();
    } catch (e) {
        return false;
    }
}