返回列表

NodeJS下创建多级目录

默认分类 2016/08/21 23:24

NodeJS下创建多级目录

var path = require('path');
var fs = require('fs');
var mkdir_p = function (dirpath, mode, callback) {
    fs.exists(dirpath, function (exists) {
        if (exists) callback && callback(dirpath);
        else mkdir_p(path.dirname(dirpath), mode, function () {
            fs.mkdir(dirpath, mode, callback);
        });
    });
};


mkdir_p('c/d/');