最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Read file names in a local folder in an HTML page - Stack Overflow

programmeradmin1浏览0评论

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?

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?

Share Improve this question edited May 23, 2017 at 12:06 CommunityBot 11 silver badge asked Aug 26, 2014 at 5:51 aakrajaakraj 131 gold badge1 silver badge3 bronze badges 2
  • 1 may this help, nodeexamples./2012/09/28/… if helpful don't forget to vote up! – Athul AK Commented Aug 26, 2014 at 6:01
  • @AthulAK That's about node.js, which is something pletely different. – user149341 Commented Aug 26, 2014 at 6:03
Add a ment  | 

2 Answers 2

Reset to default 2

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.

I'm afraid I may be the bearer of bad news for your design: The action you are requesting expressly violates the security model as specified in the File API spec. The client implementation of FileReader() must make sure that "all files that are being read by FileReader objects have first been selected by the user." (W3C File API , 13. Security Considerations: http://www.w3/TR/FileAPI/#security-discussion).

It would be a huge security risk of browser scripts could just arbitrarily open and read any file from a path without any user interaction. No browser manufacturer would allow unfettered access to the entire file system like that.

Thinking about it however, if it is all being run locally, you could use ajax to query a server side script that could return the directory you request.

发布评论

评论列表(0)

  1. 暂无评论