-1

Operating system : Windows 8.

Input-from : A text field from a html page . Input-type: text.

Output : the file that was searched.

What I want : I want the user to enter some keywords and have JavaScript search the user's local files...

Is there any way? or A javascript Library?....

And how I can query the file system about the files using Javascript..in Windows..

EDIT::

Thanks everyone for the reply... The way I get it is ,either I have to develop my own browser based in Java that has sufficient permissions.. or

I would have to implement a file crawler that indexes everything that sends that file to the a server , so that javascript can then access it through xmlhttp requests to the server ....

This was just a curiosity and I don't want to expose anyone's personal files on the Internet.

A fun project.. That all tinkered in my mind.

3 Answers3

1

This is not possible from a web page because of the browser's security restrictions. You could access the local file system with Node.js or an Electron app, but I don't know if that would suit your use case

Patrick Hund
  • 19,163
  • 11
  • 66
  • 95
0

No. That's simply not possible and even if it is, it should not be used, as it would make one's local file system open to various threats because you are directly exposing your machine on the internet. That's sufficient enough reason for a webapp not to access one's local file system in any manner whatsoever.

P.S: If you really want it, There are a few third party libraries which use Sandboxed file systems. You can try that if you want.

I havent tried it personally, but found the below link via quick googling so i am not sure if its officially supported up until now.

https://www.html5rocks.com/en/tutorials/file/filesystem/

Sam
  • 128
  • 1
  • 5
-2

Use <input type="file">, which implements ability for user to select file from local filesystem.

guest271314
  • 1
  • 15
  • 104
  • 177
  • @Quentin Really? OP is trying to select file from local filesystem. Why would they not use `` element? – guest271314 Apr 09 '17 at 16:43
  • Really. The question is asking how to do a keyword search of the user's files, not how to let the user pick a specific file that they know the name and location of. – Quentin Apr 09 '17 at 16:44
  • @Quentin The suggestion stands. Would convey to avoid implementing a procedure where users' local filesystem could be "searched", instead pass that feature implementation to existing OS file manager. Far too many issues could occur and accrue. Though can also include links to similar inquiries have posted Answer to previously. – guest271314 Apr 09 '17 at 16:46
  • I don't want the user to select the file, Instead I want the script to search for each character he types in the search field of the webpage, like Windows does... when you type character by character...and shows you the result. – Kalim Puthawala Apr 09 '17 at 16:52
  • @Quentin One way to implement such an application would require use of chromium based browser, to be able to utilize `LocalFileSystem` by calling `requestFielSystem` [jQuery File Upload Plugin: Is possible to preserve the structure of uploaded folders?](http://stackoverflow.com/questions/36098129/how-to-write-in-file-user-directory-using-javascript/). That is, user selects files which they are in agreement with allowing a web application to search through. The files are then sandboxed, and searchable by the web application when user navigates to that domain. – guest271314 Apr 09 '17 at 16:52
  • @KalimPuthawala Would suggest to not attempt to implement a web application to "search" users local filesystem for files. That would necessarily expose users' local filesystem to a web application. Instead, you can use one of several alternative approaches, including the approach at above comment; that is, allow user to search their own file system using the file manager of the OS. If user selects files, those files can then be stored in a "sandboxed" region of the browser configuration directory; this can be achieved at chromium based browsers, see http://stackoverflow.com/q/36098129/ – guest271314 Apr 09 '17 at 16:54
  • @KalimPuthawala If you are intent on being able to search user local filesystem, which would presumably include all files and directories in entire filesystem, would instead ask user to upload list of files which should be searched. – guest271314 Apr 09 '17 at 17:02
  • The curiosity for me asking such a question was that, I have already designed a webpage that looks like google's homepage, and I wanted to search user's file system... but now I think I have to learn some other things....I think a file crawler would be good. – Kalim Puthawala Apr 09 '17 at 17:02
  • Why would a user grant permission to you to be able to search through their local filesystem from a webpage? And why would you want to search a users' local filesystem? The process can be achieved, though would first prompt user to drag and drop, upload the files, or upload a list of the directories or files to be searched. You can use drag and drop for some of the functionality that you are trying to achieve. – guest271314 Apr 09 '17 at 17:04
  • @Quentin Correct link for title of link at previous comment to you http://stackoverflow.com/questions/37106121/jquery-file-upload-plugin-is-possible-to-preserve-the-structure-of-uploaded-fol/ – guest271314 Apr 09 '17 at 17:16