chrome js 读取文件夹_使用JavaScript遍历本地文件夹的文件

这篇博客介绍了如何在Chrome浏览器中使用HTML5的`download`属性读取和下载本地文件夹的内容。通过创建一个简单的HTML页面并在Chrome开发者工具中运行特定命令,用户将被询问是否允许文件下载。一旦确认,一个包含文件夹内容的HTML文件将自动下载,其内容与本地文件夹匹配。
摘要由CSDN通过智能技术生成

This blog is written based on Chrome 45.0.2454.85 m.

In HTML5 there is one additional attribute available for tag a, the “download”. By clicking on the “a” tag with “download” attribute, you can directly get download operation performed. See the simple example below:

Click Save hyperlink, the download is executed immediately and I have a downloaded file with correct name and content specified in the example.

2553698516b1f9de0d956fc604ca1827.png

4c29caa0855bbb625c5657a51cb91383.png

This useful attribute could help us to finish some task without intensive programming. For example, I need to get the file list of a given folder in my laptop via JavaScript. Here below is how to achieve it:

(1) Create a simple html page with source code below and open it via Chrome.

(2) Open Chrome development tool, type the command like below. There is a notification poped up by Chrome, asking you if you allow the file download. Click ok. Then a html file is automatically downloaded by Chrome.

fba1e7d9944479d8bb28e012501f2dc8.png

1b06e0976bb8c8c624d917564a9a8c5b.png

Open the html source code and compare its content with the actual files in your local folder. They are exactly matched.

5ec4df2bfe1526dd386d4f53120865aa.png

要获取更多Jerry的原创文章,请关注公众号"汪子熙":

b0dc89a8778f8f42f17da2081659998f.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值