Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List files in a directory using only javascript

Tags:

javascript

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?

like image 685
Anthony Garand Avatar asked May 27 '10 21:05

Anthony Garand


People also ask

How can I get a list of files in a folder?

Press and hold the SHIFT key and then right-click the folder that contains the files you need listed. Click Open command window here on the new menu. A new window with white text on a black background should appear. o To the left of the blinking cursor you will see the folder path you selected in the previous step.

How do you get a list of the names of all files present in a directory in Javascript?

To get a list of the names of all files present in a directory in Node. js, we can call the readdir method. const testFolder = './folder/path'; const fs = require('fs'); fs. readdir(testFolder, (err, files) => { files.


2 Answers

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.

like image 183
Tatu Ulmanen Avatar answered Nov 02 '22 11:11

Tatu Ulmanen


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).

like image 26
Heather Gaye Avatar answered Nov 02 '22 10:11

Heather Gaye