0

I've been looking around for quite some time now and I cant seem to find a way to get a list of subfolders from a specific directory.

An example would be, if I'm at www.mysite.com/projects and inside projects there are several folders containing individual project files.

the reason I want to do this is I was going to make a script that would add new project's names to a menu using the sub folder names.

Am I missing something ? Is this even possible with JQuery or JavaScript ?

I've gone as far as getting pathnames and locations and also had a look at ActiveXObjects but cant get anything to work on either my PC or on the server.

Any help would be appreciated.

2
  • Not possible on the client. Use a server process Commented Aug 21, 2012 at 15:38
  • Where is that directory, on the client PC or on the server? Commented Aug 21, 2012 at 15:39

2 Answers 2

3

There is no such thing as a directory in HTTP. Only resources.

Some of those resources might be an HTML document that lists some other resources (which are in a particular directory on a file system on a computer running the HTTP server). Most HTTP servers will generate such documents for you automatically.

You need to have your server generate a suitable response for a suitable request. Then use (since you mention jQuery) the ajax() method to make that request.

Then you need to parse the response. You can either use the default directory index page and then parse the HTML returned, or you can write a server side program to generate the data in a nicer format (such as JSON).

That said…

the reason I want to do this is I was going to make a script that would add new project's names to a menu using the sub folder names.

You would almost certainly be better off doing that on the server. You'll get more reliable, faster and search engine friendly results.

Sign up to request clarification or add additional context in comments.

Comments

0

ActiveX is a technology enabling JScript (the Microsoft implementation of JavaScript) to have more access to the clients computer and it only works on Internet Explorer.

Folders on the server are not like folders in a filesystem. Any folder/subfolder has the potential to contain an index.html which outputs some text (not necessarily the list of subfolders it contains).

Also most webserver configurations have an active options of not showing the subfolder list even if there is not index.html present.

What you can do is place an index.php file in that folder with the following code:

<?php
    $directories = scandir('.');
    header('Content-Type: application/json');
    echo json_encode($directories);

And you can receive this content as such:

$.getJSON('http://domain.com/path/to/folder/', function(directories) {
    do_something(directories);//
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.