const fs=require('fs');
const mkdir=(dir)=>{
return dir.split('/').reduce((a,b)=>{
return a.then((p)=>new Promise((next)=>{
p+=`/${b}`;
fs.mkdir(p,()=>next(p));
}));
},Promise.resolve('.')).then(()=>new Promise((resolve,reject)=>{
fs.stat(dir,(e,s)=>(s && s.isDirectory())?resolve():reject());
}));
};
// 测试代码
mkdir('a/b/c/d/e').then(()=>console.log('success'),()=>console.log('fail'));
相关文档
暂无
随便看看
畅言模块加载中