title: Strange error while deleting a file using the module fs in node js
body: <p>I'm trying to delete some files in a folder using the module fs.
  I need to delete a file only if it is older (modified time) that 1 minute.
  But I get a strange error.</p>
  
  <pre><code>var fs = require("fs");
  var files = fs.readdirSync("./folder");
  for (var i in files) {
    fs.stat("./folder/" + files[i], function (err, stats) {
      var currentTimestamp = Math.round(new Date().getTime() / 1000);
      var fileTimestamp = Math.round((new Date(stats.mtime).getTime() / 1000));
      if ((currentTimestamp - fileTimestamp) &gt; 60 * 1) {
        //Elimino il file di cache
        fs.unlinkSync("./folder/" + files[i], function (err) {
          if (err) {
            console.log(err);
          } else {
            console.log("File deleted");
          }
        });
      }
    });
  }
  </code></pre>
  
  <p>Unfortunately I get this error </p>
  
  <pre><code>fs.js:765
    return binding.unlink(pathModule._makeLong(path));
                   ^
  Error: ENOENT, no such file or directory
  </code></pre>
  
  <p>Why does this happen?
  How can I solve ??
  Thanks</p>
  
  <hr>
  
  <p>EDIT</p>
  
  <hr>
  
  <p>I make a log before the <code>fs.unlinkSync("./folder/" + files[i], function (err)</code> and I see that is called 2 times with the same file... but there is only one file in the folder.... with that name</p>