lib/files.js
/**
 * Find all files by mask at current folder
 * (recursive=true - including subfolders)
 * 
 * [from https://stackoverflow.com/questions/25460574/find-files-by-extension-html-under-a-folder-in-nodejs]
 */
Find all files by mask at current folder
(recursive=true - including subfolders)


Find all files by mask at current folder ( recursive = true - including subfolders )
function findFilesByMask(startPath, filter, recursive){
  let ret = [];
  if (!fs.existsSync(startPath)){
    throw new Error("No dir '" + startPath + "'");
  }
  var files=fs.readdirSync(startPath);
  for(var i=0;i<files.length;i++){
    var filename=path.join(startPath,files[i]);
    var stat = fs.lstatSync(filename);
    if (stat.isDirectory() && recursive) {
      ret = ret.concat(fromDir(filename,filter,recursive));
    } else if (filename.indexOf(filter)>=0) {
      ret.push(filename);
    };
  };
  return ret;
}
function findFilesByMask ( startPath , filter , recursive ) { let ret = [ ] ; if ( ! fs . existsSync ( startPath ) ) { throw new Error ( "No dir '" + startPath + "'" ) ; } var files = fs . readdirSync ( startPath ) ; for ( var i = 0 ; i < files . length ; i ++ ) { var filename = path . join ( startPath , files [ i ] ) ; var stat = fs . lstatSync ( filename ) ; if ( stat . isDirectory ( ) && recursive ) { ret = ret . concat ( fromDir ( filename , filter , recursive ) ) ; } else if ( filename . indexOf ( filter ) >= 0 ) { ret . push ( filename ) ; } ; } ; return ret ; }
Find all files by mask at current folder
 (recursive=true - including subfolders)
Find all files by mask at current folder ( recursive = true - including subfolders )