lib/FileSystem.js
function listTree(basePath, guard) {
    basePath = path.resolve(basePath);

    return stat(basePath).then(
        function(topStat) {
            var results = [];
            if (!guard || guard(basePath, topStat)) {
                results.push(basePath);
            }

            if (topStat.isDirectory()) {

                return list(basePath).then(
                    function(items) {
                        return Q.all(items.map(
                            function(item) {
                                var fullPath = path.join(basePath, item);
                                return listTree(fullPath, guard);
                            }
                        ));
                    }
                ).then(
                    function(sets) {
                        return Array.prototype.concat.apply(results, sets).sort();
                    }
                );
            }
            
            return results;
        },
        function() {
            // not found or not accessible, so the list is empty
            return [];
        }
    );

}
function listTree(basePath, guard) {
    basePath = path.resolve(basePath);

    return stat(basePath).then(
        function(topStat) {
            var results = [];
            if (!guard || guard(basePath, topStat)) {
                results.push(basePath);
            }

            if (topStat.isDirectory()) {

                return list(basePath).then(
                    function(items) {
                        return Q.all(items.map(
                            function(item) {
                                var fullPath = path.join(basePath, item);
                                return listTree(fullPath, guard);
                            }
                        ));
                    }
                ).then(
                    function(sets) {
                        return Array.prototype.concat.apply(results, sets).sort();
                    }
                );
            }
            
            return results;
        },
        function() {
            // not found or not accessible, so the list is empty
            return [];
        }
    );

}
function listTree ( basePath , guard ) { basePath = path . resolve ( basePath ) ; return stat ( basePath ) . then ( function ( topStat ) { var results = [ ] ; if ( ! guard || guard ( basePath , topStat ) ) { results . push ( basePath ) ; } if ( topStat . isDirectory ( ) ) { return list ( basePath ) . then ( function ( items ) { return Q . all ( items . map ( function ( item ) { var fullPath = path . join ( basePath , item ) ; return listTree ( fullPath , guard ) ; } ) ) ; } ) . then ( function ( sets ) { return Array . prototype . concat . apply ( results , sets ) . sort ( ) ; } ) ; } return results ; } , function ( ) { // not found or not accessible, so the list is empty return [ ] ; } ) ; }
Independent implementation of Kris Kowal's Q-fs listTree method. Here
to avoid depending on the whole of Q-fs for one little function.

@param basePath
@param guard
Independent implementation of Kris Kowal s Q - fs listTree method . Here to avoid depending on the whole of Q - fs for one little function .