如果目录不存在,这是创建目录的正确方法吗?它应该对该脚本具有完全的权限,并且可以被其他人读取。
var dir = __dirname + '/upload';
if (!path.existsSync(dir)) {
fs.mkdirSync(dir, 0744);
}
如果使用Node.js不存在目录,如何创建目录?
如果目录不存在,这是创建目录的正确方法吗?它应该对该脚本具有完全的权限,并且可以被其他人读取。
var dir = __dirname + '/upload';
if (!path.existsSync(dir)) {
fs.mkdirSync(dir, 0744);
}
第1696篇《如果使用Node.js不存在目录,如何创建目录?》来自Winter(https://github.com/aiyld/aiyld.github.io)的站点
相似问题
问题类别
The best solution would be to use the npm module called node-fs-extra. It has a method called
mkdir
which creates the directory you mentioned. If you give a long directory path, it will create the parent folders automatically. The module is a super set of npm modulefs
, so you can use all the functions infs
also if you add this module.