Reputation: 306
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?
Upvotes: 18
Views: 66258
Reputation: 7781
I don't know if you architecture allows it but ikf you can install and use node.js as its node API mentions, 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 dependencies.
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.
Upvotes: 1
Reputation: 1118
Very late to this party, but my google search for this exact request led me here.
The answer is "not really", but I've found the frankenstein of hacks elsewhere: If +Indexes is (or can be) enabled in the .htaccess for the folder containing the files you want to list, then use XMLHTTPRequest with the folder name as the url (which will return an html page listing the files).
Upvotes: 10
Reputation: 12499
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.
Upvotes: 0
Reputation:
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
Upvotes: 0
Reputation: 124768
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.
Upvotes: 12