-1

I am novice in javascript. Is it possible to search in a directory of html files for a text content or string? If possible can anyone suggest me how to implement this or any reference.

  • 1
    Can you show us what code you've tried so far? – Joey Ciechanowicz Apr 10 '15 at 08:58
  • 1
    More importantly, can you give a more complete example of what you are trying to accomplish? – slhck Apr 10 '15 at 08:59
  • I want to implement search function what can search in a directory for a string. Directory contents are all html files. I read the "readdir()" function of node js. But I didn't find anything like this for jquery or javascript. – Hacker Celluloid Apr 10 '15 at 09:05

2 Answers2

1

Well yes it is possible. But modern browsers will restrict access to the client's disk so no you will not be allowed to read the disk without serious changes in browser specific security settings.

Y123
  • 915
  • 13
  • 30
  • Thank you very much. Can you provide me a reference for gathering idea as I am new in javascript. – Hacker Celluloid Apr 10 '15 at 09:09
  • Sure, since ir seems you are talking of execution of JS in the web look at this discussion, http://stackoverflow.com/questions/371875/local-file-access-with-javascript. However if you are planning to run JS on a server or as a standalone application look for Node.js (http://stackoverflow.com/a/586984/1165727). – Y123 Apr 10 '15 at 16:53
1

JavaScript has no native ability access files or directories. You need an API provided by the host environment to do that.

NodeJS, for example, provides the File System module.

JavaScript embedded in a webpage has no access to the client's file system (for security reasons). It can access URLs (via XMLHttpRequest) which a web server can map onto a file system.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335