原生js怎么在指定路径下根据id创建文件夹

我现在有一个文件夹E:\img,点击网页创建按钮怎么在这个文件夹下面新建一个名为变量 id 的文件夹呢

原生js没有操作本地文件的权限

  1. 这样玩意儿只能通过nodejs来实现

浏览器运行js是没有本地文件系统接口的,你先搞清楚你的业务需求。

如果要存数据,下次打开时能快速加载,可以用LocalStorage,IndexDB等技术

如果要读写本地文件,就做标准的上传下载功能 (具体上传哪个、保存哪里是用户自己去点)

如果要完全操作本地文件系统,你可以开发个独立的程序,网页上提示下载安装运行。

如果只是学习JavaScript,先把JavaScript标准看一遍,熟悉一下有哪些功能
https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference


const fs = require("fs");
const path = require("path")
fs.mkdirSync(path.join(__dirname, "/", id))//  即可在此当前文件目录下创建一个 ID 的文件夹

有用望采纳

第一种是使用CreateTextFile方法。代码如下:

1 var fso, f1;
2 fso = new ActiveXObject("Scripting.FileSystemObject");
3 f1 = fso.CreateTextFile("E:\testfile.txt", true);
第二种是使用OpenTextFile方法,并添加上ForWriting属性,ForWriting的值为2。代码如下:

1 var fso, ts;
2 var ForWriting= 2;
3 fso = new ActiveXObject("Scripting.FileSystemObject");
4 ts = fso.OpenTextFile("E:\test.txt", ForWriting, true);
第三种是使用OpenAsTextStream方法,同样要设置好ForWriting属性。代码如下:

1 var fso, f1, ts;
2 var ForWriting = 2;
3 fso = new ActiveXObject("Scripting.FileSystemObject");
4 fso.CreateTextFile ("E:\test1.txt");
5 f1 = fso.GetFile("E:\test1.txt");
6 ts = f1.OpenAsTextStream(ForWriting, true);