0

I'm trying to use this answer to allow me to check if a given file path is a directory, however I get the following error:

fs.js:679
  return binding.lstat(pathModule._makeLong(path));
                 ^
Error: ENOENT, no such file or directory '.DS_Store'
    at Object.fs.lstatSync (fs.js:679:18)

I figured that maybe it couldn't handle hidden files well, so, after failing to find a more elegant solution, I checked if the first character in the file name was a '.'. However, the program then crashed on another file:

fs.js:679
  return binding.lstat(pathModule._makeLong(path));
                 ^
Error: ENOENT, no such file or directory 'README.md'
    at Object.fs.lstatSync (fs.js:679:18)

Why does fs.lstatSync() seem to error for such common files, and how can I make it work (correctly evaluate if the given path is a directory)?

Community
  • 1
  • 1
asaini007
  • 858
  • 5
  • 19
  • are you giving the directory path only or a file path? – Nitish Dhar May 29 '14 at 21:46
  • @NitishDhar I give it the path to what could be either a file or a directory. The purpose of the method is to determine which type it is. – asaini007 May 29 '14 at 21:53
  • Are you sure that the path exists 100% of the time? This error seems to be stemming from the fact that there is neither a file nor a folder at that path, so maybe you should check to see if it exists first before running `lstat`. – jraede May 29 '14 at 22:09
  • 1
    Looks like your giving `lstatSync()` only a filename without a path. Could it be that the files aren't in the current working directory? – mthierer May 31 '14 at 15:32

0 Answers0