0

I am working on an application that should take file system path as directory and then further processing is done on that path. The code is written into javascript. I do no want to use Node.js or any external library for validation.

We just want to give path : C:/Users/Desktop/Test_Folder

How can we validate that path in js?

We need the solution to be worked on Windows, Linux and Mac OS.

Neelam Sharma
  • 2,745
  • 4
  • 32
  • 73
  • What do you mean by "validate"? What is your Javascript environment? If you are not running node, I assume you are running it on the browser. Is that right? How would you "give" the path to your application? – Rafael Eyng Oct 15 '14 at 12:37
  • possible duplicate of [Local file access with javascript](http://stackoverflow.com/questions/371875/local-file-access-with-javascript) – Lixas Oct 15 '14 at 12:37
  • @RafaelEyng, yes we are running into browser. Validate means I want to ensure that the given directory path "REALLY" exist on my machine. We need the solution to be work on Windows, Linux and Mac OS. – Neelam Sharma Oct 15 '14 at 12:54
  • 2
    I don't think that is possible. Doing so, would allow your Javascript code to know too much about the client machine. If you can do this, you could look up the whole file system of the client, and I don't think anybody wants to enter in a website and expose his file tree. – Rafael Eyng Oct 15 '14 at 12:57
  • I agree with @RafaelEyng - it would be a huge security flaw if the web applications could access the local file system directly. No current browser would ever allow this. – fero Oct 15 '14 at 13:04
  • @fero Chrome seems to support this: https://developer.chrome.com/apps/fileSystem – lexicore Oct 15 '14 at 13:08
  • @lexicore For me this looks like an API for Chrome Apps, not for web sites being displayed in Chrome. – fero Oct 15 '14 at 13:10
  • @fero I know, I know. :) But the OP did not specify that they have a web site, he said "an application", "running into browser". So it should be possible to write a Chrome App with this API. This would work on Windows, Linux and Mac OS so all the reqs fulfilled. I don't suggest it is the right way to go (see my answer below), but it is possible and fits the question, as it is formulated. – lexicore Oct 15 '14 at 13:18

1 Answers1

1

If this is just an application in browser, then, generally, it is not possible. See the following questions:

Local file access with javascript

https://stackoverflow.com/questions/24369131/is-html5-file-api-dead

List local directory on Web Application

There was an attempt of a standardized file system API, which was discontinued. Seems like it only worked in Chrome anyway.

Update

A quote from the Chrome documentation:

Use the chrome.fileSystem API to create, read, navigate, and write to the user's local file system. With this API, Chrome Apps can read and write to a user-selected location. For example, a text editor app can use the API to read and write local documents. All failures are notified via chrome.runtime.lastError.

Community
  • 1
  • 1
lexicore
  • 42,748
  • 17
  • 132
  • 221
  • I don't know how it works, but I only can think that the user must have some way to prevent some web application to freely read his file system. Your update make it seems like this is not the case. – Rafael Eyng Oct 15 '14 at 13:30