-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!

2
  • 1
    You can click on the big checkmarks next to answers to your questions to acknowledge that they've solved your problem. Commented Jun 25, 2012 at 14:59
  • Oops, sorry. I found an answer - described in [this question][1] [1]: stackoverflow.com/questions/4482686/… Commented Jun 25, 2012 at 14:59

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

5 Comments

You could at least have mentioned the source of your answer.
@RobW Is that normal protocol? I'm new to this.
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.
I don't think I'm able to vote to close. Also, is there a way to get links to specific answers?
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").

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.