使用JavaScript遍历本地文件夹的文件
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.
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.
Open the html source code and compare its content with the actual files in your local folder. They are exactly matched.
要获取更多Jerry的原创文章,请关注公众号"汪子熙":
相关文章
- javascript中正则表达式和ruby中的一点差异
- Win10系列:JavaScript获取文件和文件夹列表
- Windows Store App JavaScript 开发:获取文件和文件夹列表
- javascript 实现 对XML文件 2级/3级联动操作
- 第一百六十一节,封装库--JavaScript,完整封装库文件
- [Javascript] Combine Objects with Object.assign and Lodash merge
- 使用JavaScript把页面上的表格导出为Excel文件[转]
- 编写javascript的基本技巧
- [Javascript] Global import
- JavaScript文件操作(1)-基础
- 使用JavaScript把页面上的表格导出为Excel文件[转]
- JavaScript Source Map 详解
- Atitit 文件上传 架构设计 实现机制 解决方案 实践java php c#.net js javascript c++ python
- 二十行代码实现JavaScript在本地生成pdf文件
- brython文档之使用 Javascript 对象
- 資料視覺化:使用Python與JavaScript 简介和目录
- 【 华为OD机试 2023】 最大连续文件之和 / 区块链文件转储系统(C++ Java JavaScript Python)
- 关于 Javascript 严格模式下多文件合并时注意
- python web py入门(31)- javascript的逻辑处理
- JavaScript----JS下载文件重命名不生效即a.download修改文件名不生效的解决办法