lib/archivist/vaults/file/directories.js
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]);
		}
	});
}
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]);
		}
	});
}
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 ] ) ; } } ) ; }
Recursively scans a directory for all files. This will then yield an array of all filenames
relative to the give rootPath or an error.

@param {String} rootPath
@param {Function} cb
Recursively scans a directory for all files . This will then yield an array of all filenames relative to the give rootPath or an error .