/**
 * Filter directories from filenames.
 * @function lib.file.filterDirectory
 * @param {string} filenames - File names to filter.
 * @param {function} callback - Callback when done.
 * @private
 */
var fs = require('fs');
exports = module.exports = function (filenames, callback) {
    if (filenames.length) {
        var filename = filenames.shift();
        fs.stat(filename, function (err, stats) {
            if (err) {
                callback(err);
            } else {
                var isDir = stats.isDirectory();
                exports(filenames, function (err, results) {
                    if (err) {
                        callback(err);
                    } else {
                        if (isDir) results.unshift(filename);
                        callback(null, results);
                    }
                });
            }
        });
    } else {
        callback(null, []);
    }
};