-1

Possible Duplicate:
Check synchronously if file/directory exists in Node.js

For example, i have a string "C:/dev/image.folder", and i want to determine, is it directory or a file (synchronously). How can i do it?

Thanks in advance!

Community
  • 1
  • 1
bonbonez
  • 6,658
  • 2
  • 15
  • 16
  • 1
    You can click on the big checkmarks next to answers to your questions to acknowledge that they've solved your problem. – Pointy Jun 25 '12 at 14:59
  • Oops, sorry. I found an answer - described in [this question][1] [1]: http://stackoverflow.com/questions/4482686/check-synchronously-if-file-directory-exists-in-node-js – bonbonez Jun 25 '12 at 14:59

1 Answers1

4
// Query the entry
stats = fs.lstatSync('/the/path');

// Is it a directory?
if (stats.isDirectory()) {
    // Yes it is
}

See T.J. Crowder's answer here: Check synchronously if file/directory exists in Node.js

Community
  • 1
  • 1
matt3141
  • 4,303
  • 1
  • 19
  • 24
  • You could *at least* have mentioned the [source](http://stackoverflow.com/a/4482701) of your answer. – Rob W Jun 25 '12 at 14:59
  • @RobW Is that normal protocol? I'm new to this. – matt3141 Jun 25 '12 at 15:00
  • It shows respect to the original author, and others can see the full version (with additional details). In this case, you should actually have voted to close the question as a duplicate, because it's an exact duplicate. – Rob W Jun 25 '12 at 15:02
  • I don't think I'm able to vote to close. Also, is there a way to get links to specific answers? – matt3141 Jun 25 '12 at 15:04
  • You can click the "link" button below each answer to link to that specific one. Also, it takes 3,000 rep to vote to close. Before you get to 3,000, you can use the "flag" link underneath questions to flag it as a duplicate (choose "doesn't belong here" and then "exact duplicate"). – Josh Darnell Jun 25 '12 at 19:37