tags:

views:

155

answers:

4

Is it possible to list the files in a directory using only javascript? To clarify, I mean list the files on the server, not the files on the clients computer. For instance:

www.domain.com/files/

contains 4 images (.jpg)

Can I make an extra page (www.domain.com/files/list.html) that lists those 4 files using javascript?

+2  A: 

No, Javascript doesn't have access to the filesystem. Server side Javascript is a whole different story but I guess you don't mean that.

Tatu Ulmanen
To clarify, I mean list the files on the server, not the files on the clients computer. For instance:www.domain.com/files/contains 4 images (.jpg)Can I make an extra page (www.domain.com/files/list.html) that lists those 4 files using javascript?
Anthony Garand
A: 

It is generally not a good idea to access client computer files via javascript for security reasons, however i suspect you can use the File System Object for that. I am not sure about browser-compatibility for that, it should work in IE only probably though.

You need to use server-side languages such as PHP, ASP.Net, JSP, etc

Web Logic
A: 

JavaScript runs inside a host environment. So if the host provides a facility to list files in this manner, then yes. But in the typical scenario where JavaScript is running in a browser with default configuration, no.

Andy West
A: 

I don't know if you architecture allow It but If you can install and use node.js as Its node API mention, you can interact with the filesystem by requiring the fs module.

This is the environment Node.js relies on:

Node eventually wants to support all POSIX operating systems (including Windows with MinGW) but at the moment it is only being tested on Linux, Macintosh, and Solaris. The build system requires Python 2.4 or better. V8, on which Node is built, supports only IA-32 and ARM processors. V8 is included in the Node distribution. To use TLS, OpenSSL are required. There are no other dependencies6

You can run It side-by-side with another web app. and this will avoid blocking your web application if the interaction with the filesystem takes too long.

microspino