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

I am creating a HTML page where I need to display the names of the files present in the specific local

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745580103a4634201.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信