0

Is it possible to use Javascript to list all the files contained in a subfolder?

I have a bunch of images that need to be linked too, but I would like it to be dynamic because the list will be changing a lot.

Thankyou!!!

AlexMorley-Finch
  • 6,785
  • 15
  • 68
  • 103

1 Answers1

1

Is it possible to use Javascript to list all the files contained in a subfolder?

No. You would usually set up a simple server side script that does the listing (e.g. using PHP's glob()), and output a JSON array, for example.

Pekka
  • 442,112
  • 142
  • 972
  • 1,088
  • It depends. If the oparating system from server is Windows, you can use Jscript. JScript is a "extension" of Javascript. – Reporter Sep 07 '11 at 09:05
  • @reporter I don't see how - JScript running on the client's browser can not do anything on server side, either – Pekka Sep 07 '11 at 09:07
  • so then, how would i pass the file name array from php to javascript? can the two even be used together? – AlexMorley-Finch Sep 07 '11 at 09:08
  • @Alex you could use Ajax to make a call to a PHP script that outputs JSON. Or you could do a ` – Pekka Sep 07 '11 at 09:09
  • @Pekka If you use an IIS you the option to use vbscript or jscript language by default. Create an .asp file (asp-classic) and read your directory. On client side, if you want to read a folder structure either you have to install an IIS or create a WSH Script that uses JScript as language. If you want use just the general javascript you can't do it (but I think you can do that with new version of javascript (Keyword: HTML5). But I'm not sure about this) – Reporter Sep 07 '11 at 09:15
  • @reporter fair enough, but I 'm fairly sure the OP referred to client-side JS specifically. What you say is a fine server-side solution, though. – Pekka Sep 07 '11 at 09:17
  • @pekka & reporter: for microsoft servers (server side) using node.js is another option. – KooiInc Sep 07 '11 at 09:36