在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ nodejs 目錄生成

nodejs 目錄生成

圖片描述

 這種目錄結(jié)構(gòu) 是怎么生成的呀?
回答
編輯回答
裸橙

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
2017年4月6日 15:58
編輯回答
朕略傻

類似于寫一個樹狀組件,遞歸配置文件

2018年6月29日 08:51
編輯回答
執(zhí)念
nodejs生成多層目錄和多層文件的通用方法

/**
*生成多層目錄

  • @param dir 多層目錄
  • @param split 分隔符,ex:'/' 對應的目錄地址:'2015/10/10'
  • @param mode 目錄權(quán)限(讀寫權(quán)限),默認0777
  • @param callback

*/
var createDirsSync = function (dir, split, mode, callback) {

console.log("創(chuàng)建目錄:" + 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);
}
2018年7月27日 15:43