1

I have some json (along with other files types) files in a directory which I need read (only json) from that directory.

It should work like an iterator, iterates over and over until all the files are read.

My Question is how can I iterate over all the files in a directory? How can I do so using JavaScript? I am using Unix system and need that thing to work for Firefox, Chrome, Safari.

(My question is not basically how to read JSON files)

kishoredbn
  • 2,007
  • 4
  • 28
  • 47
  • 1
    Web browsers don't provide facilities to do things like that. The best you can do would be to have a file input that allows multiple selections, and then manually select all the files in the target directory via the file chooser dialog. – Pointy Nov 30 '14 at 23:31
  • Nope. That won't help much. Because I need to refresh and rescan the directory in intervals. – kishoredbn Nov 30 '14 at 23:34
  • 1
    There is any ways that I can atleast store the file names in an array ? – kishoredbn Nov 30 '14 at 23:36
  • What you are asking for is impossible in Javascript because Javascript is run CLIENT side, and therefore has no real knowledge of anything on the SERVER's side. If you know PHP, you can send a JSON list of the .json files to your original query and go from there. – Jhecht Nov 30 '14 at 23:36
  • I am taking about client-side file directory. not server side. – kishoredbn Nov 30 '14 at 23:36
  • Is this for a browser addon? – Jhecht Nov 30 '14 at 23:37
  • 3
    Think about it: a web browser providing a way for code in a web page to scan the client file system ... doesn't that sound like it might be a security issue? – Pointy Nov 30 '14 at 23:37
  • @Pointy Yeah. In this application user is very well aware of that, and disabling all browser security before executing the application. – kishoredbn Nov 30 '14 at 23:39
  • @Jhecht No. this is not an addon. – kishoredbn Nov 30 '14 at 23:40
  • So far as my knowledge goes, there's no way for Javascript to do what you want it to do. – Jhecht Nov 30 '14 at 23:41
  • If your user is running windows you could do this with an .HTA – William Walseth Nov 30 '14 at 23:41
  • Does it have to be javascript, could you instead run a java applet? You could then communicate the file data to JS if you absolutely had to – Zack Newsham Nov 30 '14 at 23:46
  • There is any shell script that can help? Say the program is already running in background and keeping track of all new/deleted file entries in the directory, and writing the information in some format? My javascript can read only that one file instead to keep a track of all files in it. – kishoredbn Nov 30 '14 at 23:46
  • @ZackNewsham yes. i cannot use java applet. it has to be JS – kishoredbn Nov 30 '14 at 23:47
  • 1
    check out this link, the second answer. Will that do you? http://stackoverflow.com/questions/371875/local-file-access-with-javascript – Zack Newsham Nov 30 '14 at 23:48
  • @ZackNewsham nope. didn't helped much! – kishoredbn Dec 01 '14 at 00:02
  • 1
    Really? How about this one: http://www.w3.org/TR/FileAPI/ it sounds like it covers exactly what you want. And according to this link: http://caniuse.com/#feat=fileapi it is supported by firefox, chrome and safari – Zack Newsham Dec 01 '14 at 00:04

0 Answers0