0

I'm writing a plugin for some tool and the API is JavaScript. I need to know whether a file exists or not, and I'd like to avoid operating system calls in order to abstract from it, but using the JavaScript language instead, if possible.

Is it possible to know if a file exists locally in JavaScript, given a path?

2
  • Are you using any server side language? Commented Oct 27, 2014 at 12:23
  • What environment are you in? Browser (IE only or x-browser?) or server? Commented Oct 27, 2014 at 12:23

1 Answer 1

1

JavaScript has no native file handling functions whatsoever. Any access to the file system needs to be via an API provided by the host environment.

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

7 Comments

This is kinda wrong, depends on the enviroment. Javascript running in the browser usually has no access to the local or remote filesystem, true.
@Hless — The fact that JavaScript has no native file handling functions does not depend on the environment. What depends on the environment is what APIs are provided by the environment. JS in the browser has access to the file system through the File API (which is provided by the host environment and isn't defined by JavaScript). JS in Node has access to the file system through the File System mode which, again, is provided by the host environment and isn't native JavaScript.
That is like saying that XMLHTTP request are also not part of JavaScript and that JavaScript has no HTTP handling functions at all. Which is in essence true, but I think it makes little sense to OP.
XMLHttpRequest isn't part of JavaScript, and it isn't usually available outside of browsers. The question implies that the OP isn't working in a browser anyway, so it doesn't make sense to assume they are.
I know. Just saying the answer can be confusing depending on how you interpret it. Not everyone has this knowledge. Perhaps the 'wrong' statement was too bold, that was misinterpretation on my side.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.