Read files recursively
@param {string} path Path to read
@param {ReaddirPlusOptions|object} [userOptions]
@param {function(Error, ReaddirPlusFile[])} callback
973481
function readdirPlus(path, userOptions, callback) {
	if (libTools.isFunction(userOptions)) {
		callback = userOptions;
		userOptions = null;
	}

	var options = libTools.merge(libVars.DEFAULT_OPTIONS);

	if (userOptions) {
		userOptions.stat = normalizeSection(userOptions.stat);
		userOptions.content = normalizeSection(userOptions.content);

		if (userOptions.content) {
			normalizeArray(userOptions.content, options.content, "asText");
			normalizeArray(userOptions.content, options.content, "asBinary");
		}

		libTools.merge(userOptions, options);
	}

	if (path[path.length - 1] !== libPath.sep) {
		path += libPath.sep;
	}

	setupFn(options.readdir);
	setupFn(options.stat);
	setupFn(options.content);

	return doReadDir(path, options, function (err, results) {
		if (err) {
			return callback && callback(err);
		}
		return callback && callback(null, results);
	});

	function normalizeSection(section) {
		if (libTools.isBoolean(section)) {
			return {
				enabled: section
			};
		}
		if (libTools.isAnonObject(section) && !libTools.isBoolean(section.enabled)) {
			section.enabled = true;
		}
		return section;
	}

	function setupFn(opts) {
		if (!opts.fn) {
			opts.fn = options.sync ? opts.fnSync : opts.fnAsync;
		}
		if (options.sync) {
			opts.fn = libTools.syncWrapper(opts.fn);
		}
	}

	function normalizeArray(target, source, property) {
		if (!target[property] || target[property] === true) {
			return;
		}
		if (!libTools.isArray(target[property])) {
			target[property] = [target[property]];
		}
		else if (target[property].length === 1 && libTools.isArray(target[property][0])) {
			// array wrapped in array, replaces source value
			target[property] = target[property][0];
		} else {
			target[property] = source[property].concat(target[property]);
		}
	}
}
439292
function findAllWatchFiles(path, callback) {
  fs.stat(path, function(err, stats){
    if (err) {
      winston.error('[forewoman] Error retrieving stats for file: ' + path);
      winston.error(err.message);
    } else {
      if (stats.isDirectory()) {
        fs.readdir(path, function(err, fileNames) {
          if(err) {
            winston.error('[forewoman] Error reading path: ' + path);
	    winston.error(err.message);
          } else {
            fileNames.forEach(function(fileName) {
              findAllWatchFiles(path + '/' + fileName, callback);
            });
          }
        });
      } else {
        callback(path);
      }
    }
  });
}
122801
function readFile(path, callback) {
  nodeFs.readFile(path, function (err, binary) {
    if (err) {
      if (err.code === "ENOENT") return callback();
      return callback(err);
    }
    return callback(null, binary);
  });
}
917630
function(dirPath, callback) {

            if (!dirPath || typeof dirPath !== 'string') {
                callback("dirPath must be a string");
            } else {
                fs.readdir(dirPath, function(err, list) {
                    var dir = [];

                    if (err) {
                        callback(err, null);
                    } else {
                        list.forEach(function(item) {
                            dir.push(readNode(path.join(dirPath, item)));
                        });

                        callback(null, dir);
                    }

                });
            }

        }
1056205
function readLastChunk(path, start, end, callback) {
  nodeFs.open(path, "r", function (err, fd) {
    if (err) {
      if (err.code === "EACCES") return callback();
      return callback(err);
    }
    var buffer = new Buffer(4096);
    var length = 0;
    read();
    // Only the first read needs to seek.
    // All subsequent reads will continue from the end of the previous.
    start = null;

    function read() {
      if (buffer.length - length === 0) {
        grow();
      }
      nodeFs.read(fd, buffer, length, buffer.length - length, start, onread);
    }

    function onread(err, bytesRead) {
      if (err) return callback(err);
      length += bytesRead;
      if (bytesRead === 0) {
        return callback(null, buffer.slice(0, buffer.length + end));
      }
      read();
    }

    function grow() {
      var newBuffer = new Buffer(buffer.length * 2);
      buffer.copy(newBuffer);
      buffer = newBuffer;
    }
  });
}
970734
function fsReaddir(path, cb) {
    if (path === '/') return cb(new Error('Reading filesystem at / is disallowed to prevent mistakes.'));
    fs.readdir(path, function(err, dir) { if (err) return cb(err);
      var ab = asyncbuilder(cb);
      u.each(dir, function(name) {
        var push = ab.asyncAppend();
        fs.stat(u.join(path, name), function(err, stats) {
          var entry = !err && { name:name, type:(stats.isDirectory() ? 'dir' : stats.isFile() ? 'file' : 'other') };
          push(err, entry);
        });
      });
      ab.complete();
    });
  }
377764
function(path) {
		if (!path) return;
		
		for (var lib = IO.ls(SYS.pwd+path), i = 0; i < lib.length; i++) 
			if (/\.js$/i.test(lib[i])) load(lib[i]);
	}
765223
function(callback) {
      fs.readdir(args['<directory>'], function(err, files) {
        // error here means it does not exist, which is good.
        if (err || args['--force']) {
          return callback(null, args['<directory>']);
        }
        if (files.length > 0) {
          return callback(new Error(format('destination '
            + 'directory %s is not empty.', path.resolve(args['<directory>']))));
        }
        return callback(null, args['<directory>']);
      });
    }
1062454
function( path, callback ) {
		var match = munit.isRegExp( render.options.file_match ) ? render.options.file_match : rtestfile;

		path += '/';
		fs.readdir( path, function( e, files ) {
			if ( e ) {
				return callback( e );
			}

			async.each( files || [],
				function( file, callback ) {
					var fullpath = path + file;

					fs.stat( fullpath, function( e, stat ) {
						if ( e ) {
							callback( e );
						}
						else if ( stat.isDirectory() ) {
							render._renderPath( fullpath, callback );
						}
						else {
							if ( stat.isFile() && match.exec( file ) ) {
								munit.require( fullpath );
							}

							callback();
						}
					});
				},
				callback
			);
		});
	}
443908
function read(description, options, callback) {
  var file = vfile(description)

  if (!callback && typeof options === 'function') {
    callback = options
    options = null
  }

  if (!callback) {
    return new Promise(executor)
  }

  executor(resolve, callback)

  function resolve(result) {
    callback(null, result)
  }

  function executor(resolve, reject) {
    var fp

    try {
      fp = path.resolve(file.cwd, file.path)
    } catch (error) {
      return reject(error)
    }

    fs.readFile(fp, options, done)

    function done(error, res) {
      if (error) {
        reject(error)
      } else {
        file.contents = res
        resolve(file)
      }
    }
  }
}
279859
function readFile(path) {
  if (!path) {
    throw new Error('The passed file must not be nil to be read.');
  }
  if (!FileUtils.doesFileExist(path)) {
    throw new Error(`The passed file '${path}' must exist and must not be a directory to be read.`);
  }
  return fs.readFileSync(path, 'utf-8').toString();
}
1247216
function recursiveFileList(rootPath, cb) {
	var fileList = [];
	var errorList = [];

	var q = async.queue(function (filename, callback) {
		var filePath = path.join(rootPath, filename);

		fs.stat(filePath, function (error, stat) {
			if (error) {
				errorList.push(error);
				return callback(error);
			}

			// If not a directory then push onto list and continue
			if (!stat.isDirectory()) {
				fileList.push(filename);
				return callback();
			}

			// Otherwise recurse
			fs.readdir(filePath, function (error, files) {
				if (error) {
					errorList.push(error);
					return callback(error);
				}

				// Append list of child file onto our file list
				for (var i = 0; i < files.length; i += 1) {
					q.push(path.join(filename, files[i]));
				}

				callback();
			});
		});
	}, MAX_PARALLEL);

	q.drain = function () {
		if (errorList.length) {
			return cb(errorList);
		}

		cb(null, fileList);
	};

	fs.readdir(rootPath, function (error, files) {
		if (error) {
			return cb(error);
		}

		if (!files.length) {
			return q.drain();
		}

		for (var i = 0; i < files.length; i += 1) {
			q.push(files[i]);
		}
	});
}
510533
function loadFile(fullFilePath, callback) {
	fs.readFile(fullFilePath, "utf-8", function(err, data) {
		if (err) {
			return callback(err);
		}

		return callback(null, data);
	});
}
126315
function readLinkRecursive(path, seen) {
  seen = seen || [];

  seen.push(p.dirname(path));

  var next = readLink(path);

  trace('recur', seen, next);

  if (!next) {
    seen.push(p.basename(path));
    return seen;
  }
  return readLinkRecursive(next, seen);
}
264749
function readFiles(filePath, fileType, callback) {
    if (path_1.extname(filePath) === fileType) {
        callback(filePath);
    }
    else if (fs_1.lstatSync(filePath).isDirectory()) {
        // src is directory
        var filesOrDirectories = fs_1.readdirSync(filePath);
        filesOrDirectories.map(function (fileName) {
            var fileOrDirectory = path_1.join(filePath, fileName);
            readFiles(fileOrDirectory, fileType, callback);
        });
    }
}
1247227
function scanFolders(rootFolderPath, folders, folderFileExtensions, callback) {
        var result = [];

        console.log('Scanning:: Folders', folders);
        console.log('Scanning:: Root folder path', rootFolderPath);
        var fileExtensions = self.fileExtensions.slice();
        scanFolder();

        function scanFolder() {
            var folder = folders.shift();
            if (folder === undefined) {
//                console.log('Scanning:: Finished with result', result);
                return callback(null, result);
            }
            if(folderFileExtensions.length){
                fileExtensions = folderFileExtensions.shift();
            }
            //var path = rootFolderPath + '/' + folder;
            var path = rootFolderPath + folder;

            console.log('Scanning:: Full path to folder', path, fileExtensions);

            fs.readdir(path, function (err, list) {
                if (err) {
                    console.error("Error scanning folder: ", path);
                    return scanFolder();
                }

                var files = [];

                for (var i = 0; i < list.length; i++) {
                    if (acceptFile(path, list[i], fileExtensions)) {
                        //files.push((folder.length ? folder + '/' : folder) + list[i]);
                        files.push(path + '/' + list[i]);
                    }
                }

                result = result.concat(files);

                scanFolder();
            });
        }
    }
802499
function mkdirp(con, p, callback) {
  p = path.normalize(p);
  var dirs = p.split('/').slice(1); // remove empty string at the start.

  // console.log('dirs', dirs);

  var tasks = [];
  dirs.forEach(function(dir, i) {
    var subpath = '/' + dirs.slice(0, i).join('/') + '/' + dir;
    subpath = path.normalize(subpath); // remove extra `/` in first iteration
    tasks.push(async.apply(create, con, subpath));
  });
  async.waterfall(tasks, function(err, results) {
    if(err) return callback(err);
    // succeeded!
    return callback(null, true);
  });
}