提供一个实用的一次性同步创建多级目录的方法,收藏一下。

function makeDir(dirpath) {
    if (!fs.existsSync(dirpath)) {
        var pathtmp;
        dirpath.split("/").forEach(function(dirname) {
            if (pathtmp) {
                pathtmp = path.join(pathtmp, dirname);
            }
            else {
          //如果在linux系统中,第一个dirname的值为空,所以赋值为"/"
if(dirname){ pathtmp = dirname; }else{ pathtmp = "/"; } } if (!fs.existsSync(pathtmp)) { if (!fs.mkdirSync(pathtmp)) { return false; } } }); }else{ deleteFolderFiles(dirpath); } return true; }

 

相关文章:

  • 2022-12-23
  • 2021-09-13
  • 2022-12-23
  • 2022-01-21
  • 2021-12-07
  • 2021-12-07
  • 2022-12-23
猜你喜欢
  • 2021-09-16
  • 2021-06-12
相关资源
相似解决方案