title: learnyounode FILTERED LS
body: <p>There are many ways to write this code but I can't understand why my version is not working.</p>
  
  <p>The program should take 2 arguments from the command line. The first is the path to a folder with files, and the second arg is a file extention. The output should print only the files with the same extention as the second argument.
  When I try to execute this code with the 2 arguments i get an empty output.</p>
  
  <pre><code>var fs=require('fs');
  var path=require('path');
  var filepath=process.argv[2];
  var ext="."+process.argv[3];
  
  fs.readdir(filepath,function(err,list) {
    if (err) throw err;
    for (var i=0;i&lt;list.length-1;i++) {
      if (("."+path.extname(list[i]))==ext) {
        console.log(list[i]);
      }
    }
  });
  </code></pre>