lib/js/PagesProbe.js
function(dirname, fileRegexp, callback) {
      var t = this;

      // Get the directory at this level
      FS.readdir(dirname, function(error, fileNames) {

        // Process errors
        if (error) {
          console.error('Read dir error', error);
          return callback(error);
        }

        // Process sequentially until content is found.
        // If parallel, a deep scan would occur every time.
        var dirsToCheck = [];
        function checkNext() {

          // Done checking all filenames
          if (fileNames.length === 0) {

            // Check directories, and return true if any have content
            t.trimDirs(dirsToCheck, function(error, trimmed) {
              return callback(error, trimmed.length > 0);
            });
            return;
          }

          // Stat the next entry
          var filename = fileNames[0];
          fileNames.splice(0,1);
          var pathName = Path.join(dirname, filename);
          FS.stat(pathName, function(error, stat) {
            if (error) {
              return callback(error);
            }

            // Check for directory content or if a file should be included
            if (stat.isDirectory()) {
              dirsToCheck.push({path:pathName});
            }
            else {
              // There is content if a file exists and it matches an optional regexp
              if (!fileRegexp || fileRegexp.test(filename)) {
                return callback(null, true);
              }
            }

            // Check the next filename
            checkNext();
          });
        }

        // Kick off the first check
        checkNext();
      });
    }
function(dirname, fileRegexp, callback) {
      var t = this;

      // Get the directory at this level
      FS.readdir(dirname, function(error, fileNames) {

        // Process errors
        if (error) {
          console.error('Read dir error', error);
          return callback(error);
        }

        // Process sequentially until content is found.
        // If parallel, a deep scan would occur every time.
        var dirsToCheck = [];
        function checkNext() {

          // Done checking all filenames
          if (fileNames.length === 0) {

            // Check directories, and return true if any have content
            t.trimDirs(dirsToCheck, function(error, trimmed) {
              return callback(error, trimmed.length > 0);
            });
            return;
          }

          // Stat the next entry
          var filename = fileNames[0];
          fileNames.splice(0,1);
          var pathName = Path.join(dirname, filename);
          FS.stat(pathName, function(error, stat) {
            if (error) {
              return callback(error);
            }

            // Check for directory content or if a file should be included
            if (stat.isDirectory()) {
              dirsToCheck.push({path:pathName});
            }
            else {
              // There is content if a file exists and it matches an optional regexp
              if (!fileRegexp || fileRegexp.test(filename)) {
                return callback(null, true);
              }
            }

            // Check the next filename
            checkNext();
          });
        }

        // Kick off the first check
        checkNext();
      });
    }
function ( dirname , fileRegexp , callback ) { var t = this ; // Get the directory at this level FS . readdir ( dirname , function ( error , fileNames ) { // Process errors if ( error ) { console . error ( 'Read dir error' , error ) ; return callback ( error ) ; } // Process sequentially until content is found. // If parallel, a deep scan would occur every time. var dirsToCheck = [ ] ; function checkNext ( ) { // Done checking all filenames if ( fileNames . length === 0 ) { // Check directories, and return true if any have content t . trimDirs ( dirsToCheck , function ( error , trimmed ) { return callback ( error , trimmed . length > 0 ) ; } ) ; return ; } // Stat the next entry var filename = fileNames [ 0 ] ; fileNames . splice ( 0 , 1 ) ; var pathName = Path . join ( dirname , filename ) ; FS . stat ( pathName , function ( error , stat ) { if ( error ) { return callback ( error ) ; } // Check for directory content or if a file should be included if ( stat . isDirectory ( ) ) { dirsToCheck . push ( { path : pathName } ) ; } else { // There is content if a file exists and it matches an optional regexp if ( ! fileRegexp || fileRegexp . test ( filename ) ) { return callback ( null , true ) ; } } // Check the next filename checkNext ( ) ; } ) ; } // Kick off the first check checkNext ( ) ; } ) ; }
Determine if a directory has any contents.

This will return true if any sub-directories with contents exist, or
if any files with the specified RegExp exist.

@method hasContents
@param dirname {Path} Full path to the directory
@param fileRegexp {RegExp} Regular expression to test for files
@param callback {function(error, hasContents}} Regular expression to test for files
Determine if a directory has any contents .