简单递归,创建目录,×××××××
var fs = require('fs'),
path = require('path')
;
var targetPath = "C:\\Users\\××××\\Desktop\\ss\\oo\\fdfd\\palipala\\"
;
function mkdir(dir){
var dirname = path.dirname(dir)
;
if(!fs.existsSync(dirname)){
mkdir(dirname);
}
return fs.mkdirSync(dir,0755);
}
mkdir(targetPath);
4 回复
var fs = require('fs'),
path = require('path')
;
var targetPath = "C:\\Users\\××××××\\Desktop\\ss\\oo\\sss\\dsdas\\"
;
function mkdir(dir){
var dirname = path.dirname(dir),
stat
;
if(!fs.existsSync(dirname)){
console.log(dirname);
mkdir(dirname);
}
if(!fs.existsSync(dir)){
fs.mkdirSync(dir,0755);
}
else{
return;
}
}
mkdir(targetPath);
var fs = require('fs');
var path = require('path');
var targetPath = "/xxxx";
function mkdirs(dir) {
if(!fs.existsSync(dir)) {
mkdirs(path.dirname(dir));
fs.mkdirSync(dir);
}
}
已有一个比较多人用的模块,就是实现这个功能的: mkdirp https://github.com/substack/node-mkdirp
+1