Read file names in a local folder in an HTML page

aakraj picture aakraj · Aug 26, 2014 · Viewed 8.5k times · Source

I am creating a HTML page where I need to display the names of the files present in the specific local folder, example - C:\Users\User1\Documents\folder1 . I tried to write the code in java script but have not succeeded yet. Most of the question threads mention about "ActiveXObject" to be used but that itself does not work for me.

Reference: JavaScript: Read files in folder

Can anyone help me in achieving this?

Answer

duskwuff -inactive- picture duskwuff -inactive- · Aug 26, 2014

In general, you can't do that. Web pages do not have access to the local filesystem.

Chrome can access the contents of a directory that is selected using a file input field. However, other browsers, such as Internet Explorer and Firefox, have not implemented this feature at this time, nor is there currently any way to access a directory that was not selected by the user.

In theory, it is possible to read arbitrary files using a signed Java (not Javascript) applet. However, this requires the user to approve a series of extremely scary warning dialogs — and requires Java! — so it's really not a viable solution.