用纯 JavaScript 创建 File/Folder

Creating File/Folder with pure JavaScript

我想进一步了解 Google Chrome、Mozilla 或 Opera 中的文件系统 .我用过 FSO.js 但它没有帮助我创建、删除或列出本地文件。

有没有纯JavaScript文件系统的方法?

不,没有。曾尝试通过 Filesystem API 创建沙盒文件区域,但已被放弃。

现在,您在 browser-hosted JavaScript 代码中唯一真正的文件访问是通过 File API, which is much more limited (though still really useful). It lets you read files the user explicitly gives you permission to read via an input type="file" or drag-and-drop 事件。

据我所知,使用 Pure JavaScript 这是不可能的,即使有它的库。 & 问题可能与 this similar question 重复,@zerkms

的评论很好

If it was possible, what would prevent whosebug.com from writing an executable with virus to your autoload?

如果您想编写 JavaScript 可以在用户本地文件系统上创建文件的程序,您将需要编写一个客户端应用程序,例如 chrome app or write your program using Electron

但是,如果您想要一个跨浏览器解决方案来在用户文件系统的特定位置创建文件,那么它本身就不可能实现。

您可以:

  • 如果您只想将数据持久保存到客户端,请使用LocalStorage

  • 使用 NodeJS, Using this you will be able to require the File System core module 并使用 javascript 创建它。 [P.S。对此做一些研究]

希望对您有所帮助。