JavaScript: List Directory Contents With Apache Indexes
This can be useful if you are writing something that is entirely client-side and has to list the contents of directories on the web server. The only limitations are that:
- the web server has to be running Apache with directory indexes enabled;
- the directory to list has an index (e.g. there is no ‘index.html’ file in it); and
- the directory to list has to be on the same domain as the script (browser security policies don’t allow cross site requests).
Here is the code. It uses JQuery to make a AJAX request to the Apache directory index, and then parses it for links to the directory’s contents.
|
|
This can be tested on the console. First define a function ls:
|
|
Then try listing the contents of some directories:
|
|