I want to list the names of HTML files in a particular folder using JavaScript (in the browser)... Can anybody help me in this? Thank You
-
2Is the 'folder' on the client (i.e. where the browser is running) or the server (where the HTML and JS are loaded from)?Richard Stelling– Richard Stelling2009-10-25 14:05:54 +00:00Commented Oct 25, 2009 at 14:05
-
@rjstelling: Obviously if he is using Javascript, then he must be saying about client side.Rakesh Juyal– Rakesh Juyal2009-10-25 14:22:08 +00:00Commented Oct 25, 2009 at 14:22
-
1@Rakesh not entirely obvious, as there does exist server side javascript - Rhino,SpiderMonkey, etc.JAL– JAL2009-10-25 14:54:35 +00:00Commented Oct 25, 2009 at 14:54
3 Answers
If you're using Javascript that's running in the browser, there's no way to "open a folder". You have to obtain data about the folder contents through some data structure or by doing something like parsing a server generated folder index in HTML.
If you're using Javascript that's running on a non-browser engine (such as jscript, rhino, etc.) then you have to be more specific in the question as the answer will obviously depend on whether the engine where your script is running provides objects to access the filesystem or not.
6 Comments
This is what you are asking for:
http://www.irt.org/articles/js014/index.htm
Also read on FSO
But yes, if you can't use FSO if ActiveX is disabled on client system.
Comments
Javascript can't interact with the OS while running inside a browser, due to security concerns.
It can get a list from the server and display that to the client on the browser, but, to get a directory structure from the client computer to the browser would require some other application reading the directory structure and sending it to the server, and the server sending it to the browser.
Now, if you are using Actionscript it is possible to read the hard drive, and I expect that Silverlight would allow you to do this also, but I don't know.