nodejs 目录生成

图片描述

 这种目录结构 是怎么生成的呀?
阅读 3.1k
3 个回答

nodetree 能满足需求。
使用:

var nodetree = require('nodetree');
nodetree(process.cwd());

输出类似如下:

├── favicon.ico
├── html
│   ├── about.html
│   └── index.html
├── image
│   ├── github.png
│   └── robot.png
├── manifest.json
├── script
│   ├── commonjs
│   │   └── printMe.js
│   └── entryjs
│       ├── about.js
│       └── index.js
└── style
    └── index.css
新手上路,请多包涵

类似于写一个树状组件,递归配置文件

nodejs生成多层目录和多层文件的通用方法

/**
*生成多层目录

  • @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);
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题