nodejs生成多层目录和生成文件的通用方法
2015-10-17 21:36
411 查看
/** *生成多层目录 * @param dir 多层目录 * @param split 分隔符,ex:'/' 对应的目录地址:'2015/10/10' * @param mode 目录权限(读写权限),默认0777 * @param callback */ var createDirsSync = function (dir, split, mode, callback) { console.log("创建目录:" + dir); if (!fs.existsSync(dir)) { var dirArr = dir.split(split); var pathtmp; async.forEach(dirArr, function (item, cb) { console.log( item); if (pathtmp) { pathtmp = path.join(pathtmp, item); } else { pathtmp = item; } if (!fs.existsSync(pathtmp)) { if (!fs.mkdirSync(pathtmp, mode)) { cb(null, item); } else { } } }, function (err) { callback(err); }) } else { callback(null); } }
相关文章推荐
- Nodejs中间件Connect
- VB读取XML文件,selectNodes获取节点属性
- Node.js代码总结
- Reverse Nodes in k-Group
- nodejs中express入口文件及supervisor插件问题
- Swap Nodes in Pairs
- Remove Nth Node From End of List
- nodejs支持ssi实现include shtml页面
- <LeetCode><Easy> 19 Remove Nth Node From End of List
- LeetCode解题报告--Swap Nodes in Pairs
- [leetcode] Swap Nodes in Pairs
- assert()断言函数以及NODEBUG用法总结
- hadoop nameNode 无法启动
- 使用 AngularJS & NodeJS 实现基于 token 的认证
- nodejs 计算内存使用率
- Reverse Nodes in k-Group
- 使用node.js的bodyParser中间件读取post数据解析
- Node.js 都应用在什么项目上?这些项目为什么选择 Node.js?
- NodeJS优缺点及适用场景讨论
- 让Node模块在浏览器运行----browserify